SQL Server数据库邮件:HTML不在Outlook和Gmail中呈现
问题描述:
我在SQL Server中使用数据库邮件并尝试发送电子邮件。我创建了这个简单的HTML邮件用于测试目的:SQL Server数据库邮件:HTML不在Outlook和Gmail中呈现
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'
然而,HTML不是呈现在在Outlook 2013和Gmail。其显示如下:
为什么它不起作用?
答
设置body_format
属性为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'
运行代码snippetCopy片段来回答
我相信你需要设置一个更多的财产,以HTML而不是纯文本 – ElenaDBA