问题
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.
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
true;
strImagePath = Server.MapPath("\") & "\images\mypic1.jpg"
response.write strImagePath ' try
myMail.AddRelatedBodyPart strImagePath, "mypic1.jpg", 0
来源:https://stackoverflow.com/questions/10904763/asp-embed-image-to-cdo-message-email