Reputation:
I have an HTML Mail template, with a place holder for the image. I am getting the image I need to send out of a database and saving it into a photo directory. I need to embed the image in the HTML Message.
I have explored using an AlternateView:
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<HTML> <img src=cid:VisitorImage> </HTML>");
LinkedResource VisitorImage = new LinkedResource(p_ImagePath);
VisitorImage.ContentId= "VisitorImage";
htmlView.LinkedResources.Add(VisitorImage);
Upvotes: 23
Views: 12905
Reputation: 2431
Try this:
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);
Upvotes: 22