我有一个HTML Mail模板,带有图像的占位符。我正在获取我需要从数据库发送的图像并将其保存到照片目录中。我需要将图像嵌入HTML消息中。
我已经探索过使用AlternateView:
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<HTML> <img src=cid:VisitorImage> </HTML>");
LinkedResource VisitorImage = new LinkedResource(p_ImagePath);
VisitorImage.ContentId= "VisitorImage";
htmlView.LinkedResources.Add(VisitorImage);
答案 0 :(得分:22)
试试这个:
LinkedResource objLinkedRes = new LinkedResource(
Server.MapPath(".") + "\\fuzzydev-logo.jpg",
"image/jpeg");
objLinkedRes.ContentId = "fuzzydev-logo";
AlternateView objHTLMAltView = AlternateView.CreateAlternateViewFromString(
"<img src='cid:fuzzydev-logo' />",
new System.Net.Mime.ContentType("text/html"));
objHTLMAltView.LinkedResources.Add(objLinkedRes);
objMailMessage.AlternateViews.Add(objHTLMAltView);