T-SQL to send email

Hello,

Below piece of t-sql will help you send email. I use this in some test jobs whenever I don’t want to send unwanted emails to the entire DBA team. An instance of this is when I am testing some purge jobs I would only check notify when job fails in the SQLServer agent job notification of that specific job. But the prior step would be to add this piece and route it when any step of the job fails. So the @subject would be ‘Hey your job failed’ and the @recipient would just be me. This step will however succeed and none of the DBA team would get these unwanted emails even though I am using the common profile.


EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Enter the profile here eg:DBGroup',
@subject = 'Enter the subject here',
@body = 'Enter your body here',
@recipients = 'Enter your email here',
@body_format = 'text'

Hope this helps.

Advertisements
This entry was posted in SQL Server DBA Stuff and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s