Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying HTML formatting in email's body

I am still trying to figure out, why i cannot apply HTML formatting in the body of a custom email. I am sure i am missing something, or i need a new pair of eyes!

Here is the info added to the <head> of the web page

<head runat="server">
    <link href="~/MyStyle.css" rel="stylesheet" type="text/css" />
</head>

Mystyle.css contains the following

span.orange
{
    color: #FF6D06;
    font-family: tahoma;
    font-size: 10pt;
}

and here comes the body part...

Dim HtmlString as string = "<span class='orange'>This one should be painted</span>" 

which is sent by using Net.Mail

Dim objMail As New Mail.MailMessage (blah, blah blah)
objMail.IsBodyHtml = True

UPDATE: First of all thank you for your comments. The email itself is not in any way referenced with the style sheet in any way. So what options do i have besides attaching the style sheet to the email?

like image 870
OrElse Avatar asked Dec 19 '09 21:12

OrElse


3 Answers

When I've done this, I've typically embedded the CSS in the body of the email:

<html>
<head>
<style type="text/css">
span.orange
{
    color: #FF6D06;
    ...
}
</style>
</head>
...

Avoid referencing external entities (like stylesheets, images, etc.) in HTML email. Those references may not be available, depending on the user's mail agent settings. Also, learn about the HTML support in mail agents. It may not be as rich as you expect. Here's some information on Outlook, for instance.

like image 120
Michael Petrotta Avatar answered Oct 06 '22 12:10

Michael Petrotta


As noted by others, defining your styles inline is the best option. Here are a couple of articles that you might find useful:

Rock Solid HTML Emails

Guide to CSS support in email clients

like image 38
Simon Forrest Avatar answered Oct 06 '22 11:10

Simon Forrest


It appears you are going about this incorrectly.

Your CSS should be inline, and not external. Then you just have all of your HTML and CSS styles as the body of your email, and it will work.

You really want to avoid referencing outside files as many email applications will block the references.

like image 32
Clarence Klopfstein Avatar answered Oct 06 '22 12:10

Clarence Klopfstein