--################################################################################################### --envtestemail extracted from \\Us1.autonation.com\workgroups\DataManagement\Governance\Scripts\SSMSTools_Lowell_2020-09-03.ses on 2020-09-03 10:41:23 --################################################################################################### --desc: creates html command to generate and send an email --EXECUTE AS login='bi360sa' DECLARE @HTMLBody VARCHAR(MAX), @HTMLSubject VARCHAR(MAX), @TableHead VARCHAR(MAX), @TableTail VARCHAR(MAX); SET @TableTail = ''; SET @HTMLSubject = CONVERT(VARCHAR(30),@@SERVERNAME) + ' Sample Email' SET @TableHead = '' + '' + '' + '' +'

' + CONVERT(VARCHAR(30),@@SERVERNAME) + ': started at' + CONVERT(VARCHAR,getdate(),120) + ';

' + '' + '' + '' + ''; SET @HTMLBody = 'blah'; SELECT @HTMLBody = @TableHead + @HTMLBody + @TableTail; IF DATENAME(dw,GETDATE()) NOT IN ('Saturday','Sunday') BEGIN -- return output --Select @HTMLBody --now the email itself: EXEC msdb.dbo.sp_send_dbmail --@profile_name='HPP Database Mail', @recipients='Lowell Izaguirre;', @subject = @HTMLSubject, @body = @HTMLBody, @body_format = 'HTML'; END; --IF
This is a simple Alert testing email functionality.