tags:

views:

1180

answers:

1

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);
+4  A: 

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);

Complete article can be found here

Scott and the Dev Team