English 中文(简体)
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?

最佳回答

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.

问题回答

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

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.

Most mail-readers (both desktop-based and web-based) don t deal great with CSS : it s generally better to not use and external CSS and use inline styles, it s often better to use tables for formating instead of divs, ...

And, here, where is your CSS ? Is it at least on a server somewhere ?
(i.e. it should not be only on your local machine, but accessible via some kind of URL)

Color attribute won t work for e-mails, for most mail agents it might work the first time the e-mail is sent but it ll be ignored if the e-mail is forwarded.

Best thing is to use very old HTML tags and tables to format and style the e-mail, such as pre-tableless code.

Sad but true, support for e-mails is still incredibly poor.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签