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:
- In Outlook the padding of 40 pixels that I set above doesn't show
- 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!