我有这个 html,我作为邮件发送(参见 fiddle ),我在其中使用了 2 个外部图像(一个用于公司 Logo ,一个用于表格背景): :
http://jsfiddle.net/UTSnK/
<img src="http://www.hawkaviation.com/assets/static-header.jpg" alt="Hawk Aviation""/></a>
<table border="0" cellspacing="0" cellpadding="0" style="background:rgba(55, 20, 240, 0.99) url('http://www.hisplaceautorepair.com/images/auto/Primary_Images/napa_bg.jpg'); padding: 38px">
我将它从代码发送到许多电子邮件客户端:gmail、yahoo、ios。只有outlook客户端不显示图片:
我该如何克服它?这与我发送它的方式(通过 c# 代码)或图像链接到 html 的方式有关吗?
我会很感激一步一步的回答。问候,奥马尔。
这就是我在 Outlook 中实现它的方式
private MailMessage report = new MailMessage();
...
if (this.report.IsBodyHtml)
{
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(this.bodyText.ToString(), this.report.BodyEncoding, "text/html");
LinkedResource headerImageLink = new LinkedResource(ConfigReader.GetConfigValue("ImageLocation") + "\\MyBanner.gif", "image/gif");
headerImageLink.ContentId = "headerImageId";
headerImageLink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
LinkedResource footerImageLink = new LinkedResource(ConfigReader.GetConfigValue("ImageLocation") + "\\horizontal_c.gif", "image/gif");
footerImageLink.ContentId = "footerImageId";
footerImageLink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
htmlView.LinkedResources.Add(headerImageLink);
htmlView.LinkedResources.Add(footerImageLink);
this.report.AlternateViews.Add(htmlView);
}
引用上图的 HTML 是:
<IMG src=\"cid:headerImageId\"/>
headerImageId 指的是 LinkedResource 的 ContentId。
基本上,您是将图像转换为文本以进行传输,这些文本在到达客户端时会重新构造为图像。
我是一名优秀的程序员,十分优秀!