Microsoft SQL Server DBMAIL Send HTML email

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

HTML content must be passed to sp_send_dbmail

SQL Server 2012
DECLARE @html VARCHAR(MAX);
SET @html = CONCAT
(
    '<html><body>',
    '<h1>Some Header Text</h1>',
    '<p>Some paragraph text</p>',
    '</body></html>'
)
SQL Server 2012
DECLARE @html VARCHAR(MAX);
SET @html =
    '<html><body>' +
    '<h1>Some Header Text</h1>' +
    '<p>Some paragraph text</p>' +
    '</body></html>';

Then use the @html variable with the @body argument. The HTML string can also be passed directly to @body, although it may make the code harder to read.

EXEC msdb.dbo.sp_send_dbmail 
    @recipients='[email protected]',  
    @subject = 'Some HTML content',  
    @body = @html,  
    @body_format = 'HTML';  


Got any Microsoft SQL Server Question?