ASP embed image to CDO.Message email

5.5k views Asked by At

I'm using ASP classic and CDO to send email with CreateMHTMLBody method. I have couple of images in my email which some of them are static and would not change but some of them will change based on email content. Some of the mail softwares like iCloud showing the pictures as attachment even though I have them all with full path url address. I've used AddRelatedBodyPart but right now they show the images in the place that thy have to be but still they show the images in attachment as well. I want the picture just show in body of email not in attachment. Does any one know how to fix this? Here is the example of my code:

Set myMail=CreateObject("CDO.Message")
myMail.Subject= "Subject of Email"
myMail.From= "[email protected]"
myMail.To= "[email protected]"
myMail.CreateMHTMLBody "http://www.mysite.com/email.html"

strImagePath = Server.MapPath("\") & "\images\mypic1.jpg"
myMail.AddRelatedBodyPart strImagePath, "my_pic_1", 0

strImagePath = Server.MapPath("\") & "\images\mypic2.jpg"
myMail.AddRelatedBodyPart strImagePath, "my_pic_2", 0

myMail.Send
set myMail=nothing

Thanks in advance for your time and help.

4

There are 4 answers

0
fatman45 On

I know this question is old but maybe you (or someone else) is still looking for the answer:

myMail.Configuration.Fields("urn:schemas:httpmail:content-disposition-type")="inline"
myMail.Configuration.Fields.Update

This should cause most mail clients to not render images as attachments.

1
Ümit Gündüzlü On
true;

 strImagePath = Server.MapPath("\") & "\images\mypic1.jpg"

response.write strImagePath ' try

 myMail.AddRelatedBodyPart strImagePath, "mypic1.jpg", 0
0
AnthonyWJones On

The CreateMHTMLBody is not what you need. This method will create a multipart message fetching the URL and post processing the HTML returned. It fetches the resource for every img src it finds, encodes the returned resource as a body part and updates the HTML img src to point at the body part.

Also CreateMHTMLBody is not a good thing to use in ASP code since it uses the WinINET Http stack to fetch resources, WinINET should not be used from ASP code.

What you really need is to use something like WinHTTP to fetch the HTML resource and then assign that to the Message's HTMLBody property.

4
Diodeus - James MacFarlane On

In order to have images in emails, you have to use inline IMG tags in the body of the message with the fully-qualified path to the image (http://...). DO NOT treat them as attachments.