Has anyone found a good way of embeding CSS in a programatically produced email. The best way I have found is to put the style code into a resource file and call it into the code.
An emample would be
Dim objBuilder
objBuilder = New StringBuilder
objBuilder.Append(Resources.SystemEmail.CSSStyle)
objBuilder.Append("My Styled Email")
Dim _Body As String = objBuilder.ToString()
This would build the body of the email
Is there any way to make a template file for an email or a better way to call a style sheet into one.
The code in my .resx file would be
<STYLE TYPE="text/css">
<!--
body
{
font-family: Tahoma, Verdana, Arial;
font-size: 10pt;
padding: 3px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
-->
</STYLE>
And calling this into the string would call this inline
And with the answers below to send the message I would use this
Dim client As New SmtpClient("localhost")
Dim toAddr As New MailAddress(MailRecipients)
Dim fromAddr As New MailAddress(MailFrom)
Dim message As New MailMessage(fromAddress, toAddress)
message.Subject = "The Subject"
message.Body = _Body
message.IsBodyHtml = True
message.BodyEncoding = System.Text.Encoding.UTF8
client.Send(message)
The only way we've been successful is to include the CSS inline. Document Header style CSS inclusion isn't consistent or reliable.
Also, make sure your email headers are set to: Content-type: text/html; charset=ISO-8859-1
EDIT UTF-8 is also a good option. The KEY point of that statement is the Content-type being set to text/html
Here is a comprehensive guide on which css styles are supported by each email client: http://www.campaignmonitor.com/css/
A guide on what you will need to know: http://www.campaignmonitor.com/design-guidelines/
There is also a large collection of free pre-built templates that you can use as a reference: http://www.campaignmonitor.com/templates/
Finally, the same company provides a testing tool that will show you how your message will show up in each email client for a reasonable fee: http://www.campaignmonitor.com/testing/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With