0
我嘗試使用嵌入式圖像發送電子郵件。圖片從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("[email protected]", "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);
}
的HT這些'img'元素上的ml src標記看起來不正確。 – gwin003 2013-05-09 14:23:15
@ gwin003 ...那麼...它應該如何在嵌入圖像的情況下呢?你可以建議嗎? – 2013-05-09 14:24:37
@MichaelTodd對不起...一切都在密碼中,你可以看看這些嗎? – 2013-05-09 14:27:57