0

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= "from@site.com"
myMail.To= "to@site.com"
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.

Jay
  • 1,384
  • 1
  • 17
  • 30

4 Answers4

0

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.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • I have used the full path like but still I get attachment instead of body of email. In gmail everything is correct but in Yahoo it shows in body of email and attached image but in iCloud it shows only in attachment!!!! – Jay Jun 05 '12 at 21:02
  • You're missing http:// in your SRC and you DO NOT NEED to attach *ANY* images, the mail client will find them on the web automatically. – Diodeus - James MacFarlane Jun 05 '12 at 21:04
  • I know. I know I dont need to attach any image in my email. Thats my problem. I don't attach any image but still mail clients like yahoo or iCloud treat them as attachment. I just forgot to add "http://" in my example above. My images have "http://" in their src. I dont know, may be its because im using CreateMHTMLBody method. Any idea? – Jay Jun 05 '12 at 21:12
  • There is a great testing tool called "Inbox preview" available on exacttarget.com. (not free) that will actually render your email in a bunch of different client and generate screenshots for you. It's worth using if emails are going to be part of any ongoing marketing activities. – Diodeus - James MacFarlane Jun 06 '12 at 13:17
0

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.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
0

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.

fatman45
  • 68
  • 1
  • 9
0
true;

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

response.write strImagePath ' try

 myMail.AddRelatedBodyPart strImagePath, "mypic1.jpg", 0
Brad Solomon
  • 38,521
  • 31
  • 149
  • 235
  • 4
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – dpr Aug 29 '17 at 14:34