我尝试发送带有嵌入图像的电子邮件。图像来自List<Bitmap>
,我相信它们 100% 存在。
不知何故,当我收到电子邮件时,我根本看不到任何图像,HTML 看起来像
<img alt="" hspace="0" src="http://image0" align="baseline" border="0">
<br />
<img alt="" hspace="0" src="http://image1" align="baseline" border="0">
<br />
有什么线索吗?
C#就像
var smtp = new SmtpClient();
var msg = new MailMessage(new MailAddress("support@mysite.com", "mysite.com Support"),
new MailAddress(email, email));
msg.Subject = "No worries, man";
msg.IsBodyHtml = true;
var bodyBuilder = new StringBuilder();
for (int i = 0; i < pages.Count; i++)
bodyBuilder.AppendLine(string.Format("<img alt=\"\" hspace='0' src='cid:image{0}' align='baseline' border='0'><br />",i));
var htmlView = AlternateView.CreateAlternateViewFromString(bodyBuilder.ToString(), null, "text/html");
var index = 0;
foreach (var page in pages) // where page is List<Bitmap>
{
var memoryStream = new MemoryStream();
page.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);
var imagelink = new LinkedResource(memoryStream, "image/png");
imagelink.ContentId = string.Format("image{0}", index);
imagelink.TransferEncoding = TransferEncoding.Base64;
htmlView.LinkedResources.Add(imagelink);
index++;
}
msg.AlternateViews.Add(htmlView);
try
{
smtp.Send(msg);
return Json("true", JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
logger.Error(ex.Message, ex);
return Json("false", JsonRequestBehavior.AllowGet);
}