SQL Server数据库邮件:HTML无法在Outlook和Gmail中呈现

时间:2016-07-07 19:13:08

标签: html email outlook html-email database-mail

我在SQL Server中使用数据库邮件并尝试发送电子邮件。我已经为测试目的创建了这个简单的html消息:

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 = 'myemail@gmail.com'
, @subject = 'Test', @body = @body, @reply_to = 'noreply@myserver.com', 
@from_address = 'noreply@myserver.com', @profile_name= 'My SMTP'

但是,Outlook 2013和Gmail上都不呈现html。它显示了这个: enter image description here

为什么不起作用?

1 个答案:

答案 0 :(得分:1)

body_format属性设置为HTML

EXEC msdb.dbo.sp_send_dbmail @recipients = 'myemail@gmail.com'
, @subject = 'Test', @body = @body, @body_format='HTML', @reply_to = 'noreply@myserver.com', 
@from_address = 'noreply@myserver.com', @profile_name= 'My SMTP'

运行code snippetCopy代码段以回答