I have a stored procedure for sending an email from SQL Server.
The email needs to be sent in HTML format.
But the email when shown on the recipient’s, it does not have the CSS styles applied to the email. It simply shows it as simple text.
Find my code below:
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';
Thank you.
I figured out that internal or embedded styles can not be applied to the body of the email.
Instead I have used inline styles which is now working. The email is now being displayed as it should.
Find code below: