How do I embed an image in a .NET HTML Mail Message?
Asked Answered
K

1

23

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);
Kain answered 19/9, 2008 at 18:10 Comment(0)
P
22

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);
Prestissimo answered 19/9, 2008 at 18:17 Comment(1)
Looks like link is dead.Princeling

© 2022 - 2024 — McMap. All rights reserved.