CSS 样式不适用于 sp_send_dbmail (SQL Server) 中的电子邮件

Dav*_*oye 1 t-sql sql-server sql-server-2008

我有一个用于从 SQL Server 发送电子邮件的存储过程。

电子邮件需要以 HTML 格式发送。

但是当显示在收件人的电子邮件中时,它没有应用于电子邮件的 CSS 样式。它只是将其显示为简单的文本。

在下面找到我的代码:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'mail-profile-name' ,
@recipients = 'myemail@gmail.com' ,
@body = '<html>
<head>
<style type="text/css">
    .style1
    {
        font-weight: normal;
    }
</style>
</head>
<H1><span class="style1">Sales</span> Reports</H1><body bgcolor=yellow>
<table border = 2><tr><th>Product ID </th><th>SaleAmount</th></tr></table></body>    </html>' ,
@subject = 'AUTOMATED ALERT' ,
@body_format = 'HTML';
Run Code Online (Sandbox Code Playgroud)

谢谢你。

Dav*_*oye 5

我发现内部或嵌入的样式不能应用于电子邮件的正文。

相反,我使用了现在正在工作的内联样式。电子邮件现在正按原样显示。

在下面找到代码:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'mail-profile-name' ,
@recipients = 'myemail@gmail.com' ,
@body = '<html>
<H1 style="color: #0000FF"><span style="font-weight: normal;">Sales</span> Reports</H1><body>
<table border = 2><tr><th style="background-color: #00FF00">Product ID </th>
<th style="background-color: #FF0000">SaleAmount</th></tr></table></body>    </html>' ,
@subject = 'AUTOMATED ALERT' ,
@body_format = 'HTML';
Run Code Online (Sandbox Code Playgroud)