Technical Article

Sending Job Failed Information Through E-Mail Using T-SQL

,

This script is useful to send an email when there is a job failure.

DECLARE

@SN    NVARCHAR(100),

@MSG    NVARCHAR(100),

@SQL    NVARCHAR(250)



SET    @SN    = @@SERVERNAME

SET    @MSG    = @SN + 'Your Message'

SET     @SQL     = 'JobName'+ @SN + ' failed - please review this job'



EXEC    msdb.dbo.sp_send_dbmail

    @profile_name        ='ProfileName',

    @recipients        ='recipient@gmail.com;recipient1@gmail.com ',
  
   @copy_recipients        ='',

    @blind_copy_recipients    ='',

    @subject            =@MSG,

    @body            =@SQL,

    @body_format        ='HTML',

    @importance        ='HIGH',

    @sensitivity        ='NORMAL',

    @file_attachments        =''

Rate

2.1 (10)

You rated this post out of 5. Change rating

Share

Share

Rate

2.1 (10)

You rated this post out of 5. Change rating