Hussein Salman
Hussein Salman

Reputation: 8246

SQL Server Database Mail: HTML not rendering in Outlook and gmail

I am using Database Mail in SQL Server and trying to send emails. I have created this simple html message for testing purposes:

declare @body nvarchar(1000)
select @body = 

'<html><body>
<h3>Test Email</h3>
<table border="1">
 <tr>
  <th>ID </th>
  <th>Name</th>
 </tr>
 <tr>
  <td>1</td>
  <td>John</td>
 </tr>
 <tr>
  <td>2</td>
  <td>Marry</td> 
 </tr>
</table>
</body></html>'

EXEC msdb.dbo.sp_send_dbmail @recipients = '[email protected]'
, @subject = 'Test', @body = @body, @reply_to = '[email protected]', 
@from_address = '[email protected]', @profile_name= 'My SMTP'

However, html is not rendered on both Outlook 2013 and Gmail. Its showing this: enter image description here

Why is it not working?

Upvotes: 0

Views: 1856

Answers (1)

Coding Duchess
Coding Duchess

Reputation: 6909

set body_format property to HTML

EXEC msdb.dbo.sp_send_dbmail @recipients = '[email protected]'
, @subject = 'Test', @body = @body, @body_format='HTML', @reply_to = '[email protected]', 
@from_address = '[email protected]', @profile_name= 'My SMTP'

Run code snippetCopy snippet to answer

Upvotes: 1

Related Questions