
-- Here is a sample SQL code segment that sends a email from the SQL server
-- Of course, you must have created a database mail profile at this time.
Declare @Message Varchar(100);
set @message = 'Enjoy a wonderful Spring break!';
EXEC msdb.dbo.sp_send_dbmail
  @profile_name = 'yourProfile',
  @recipients = 'GemMine@gmail.com', -- safe to send email to this address
  @subject = 'One week escape',
  @body = @message,
  @body_format = 'HTML' ;


-- After a send_dbmail has been executed successfully,
-- you can verify the status with the following SQL statements:

SELECT * FROM msdb.dbo.sysmail_profile  -- lists all database mail profiles

SELECT * FROM msdb.dbo.sysmail_allitems  -- lists all mail items activated

SELECT * FROM msdb.dbo.sysmail_sentitems  -- lists all delivered emails

SELECT * FROM msdb.dbo.sysmail_unsentitems -- lists all undelivered emails


-- Additional diagnostic views that may provide useful information
select * from sys.triggers -- displays all triggers

select * from sys.sysusers -- shows allusers and their permissions

select * from sys.sysmessages -- all system message logs

select * from sys.messages -- same as sys.sysmessages

select * from sys.events -- lists the events occurred

