I have code which uses system.net.mail to send html formatted emails. They show up as desired in web-based email services (GMail,Hotmail, etc) but in Outlook the html, specifically the image, doesn't appear correctly.

When You double-click the email to enlarge it the image doesn't expand with the rest of the div. the html is as follows:

strHtml = "<html><body><div style='background-color:#EDF4F8;color:#fff;width:740px;'>";
strHtml += "<div style='width:100%;'><img src='cid:banner' width='100%'/></div><div"    
strHtml += "style='padding:40px;'>";
strHtml += "<div style='font-size:9pt;font-family:'Verdana',sans-serif;padding-top:7;'>";
strHtml += "</div>";
strHtml += "</div></div></body></html>";

SmtpClient client = new SmtpClient("xxx");
client.Credentials = new NetworkCredential("x", "x", "xxx");
MailMessage message = new MailMessage();
message.From = new MailAddress("xx");
message.To.Add("xx");
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(strHtml, null, "text/html");
LinkedResource r = new LinkedResource("c:\\blah.png", "image/png");
htmlView.LinkedResources.Add(r);
message.AlternateViews.Add(htmlView);
message.IsBodyHtml = true;
mailServer.Send(message);

Again, this works fine in GMail, Hotmail etc, the linked resource image shows up and everything, but not Outlook. Specifically:

  1. In Outlook the padding of 40 pixels that I set above doesn't show
  2. if you double click the email to open it in its own window the banner image from the html above does't expand with the rest of the email. It stays at its size when it was created (740 pixels). In all the other email clients, the image expands the width of the div.

What am I missing here? Why would this show up in the other clients but not Outlook? Does Outlook embed something extra into the email that's throwing off the HTML? I know that at least SOME of the html is working because the background color that I set i showing up and I've fiddled with text color and font weight and they all show up in Outlook.

Thanks!

有帮助吗?

解决方案

What you're missing is that web based browsers use your web browser to render the image. Outlook does not use a web browser, but rather a much more limited custom HTML rendering engine. You will probably find similar problems with other application based clients that do not use the built-in HTML rendering (each one does things a little differently).

You may find these links helpful:

http://www.campaignmonitor.com/css/ http://www.versapay.com/developer-blog/the-art-and-science-of-email-rendering-across-email-clients/

There is a service that shows you previews in major clients, but it isn't free http://litmus.com/email-testing

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top