/    Sign up×
Community /Pin to ProfileBookmark

Embed Images in CDO mail message

To those who can help me here, I’d greatly appreciate it!

I’ve been doing some research but I’m having a hard time finding a good tutorial on how to embed images into a CDO generated email.

I’ve found ways to attach images, but I don’t want them included as attachments, rather, I want them embedded (where the image tag might read <img src=”cid:image001.gif”…).

Using CDONTS or CDOSYS is there a good example someone could post, or a tutorial on how to achieve this?

Thank you,
Greg

to post a comment

18 Comments(s)

Copy linkTweet thisAlerts:
@SoreheadFeb 13.2008 — Just host the images externally and give the src a url to access the image.
Copy linkTweet thisAlerts:
@yamaharussFeb 13.2008 — [CODE]Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
Flds("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
Flds( _
"http://schemas.microsoft.com/cdo/configuration/smtpserverpickupdirectory") _
= "c:inetpubmailrootpickup"
Flds.Update

Set iMsg.Configuration = iConf
iMsg.To = "[email protected]"
iMsg.From = "[email protected]"
iMsg.Subject = "Hello World"
iMsg.HTMLBody = "Here is my image <img src="http://www.mysite.com/images/image.jpg">"
iMsg.Send [/CODE]
Copy linkTweet thisAlerts:
@gregw74authorFeb 13.2008 — Up until now this is how I've been including images in emails and for the most part it works fine. Though, with some client-side SPAM filters, the hotlinking is seen as a privacy threat and so the images are either blocked (unless users 'allow' images from such domanis); or sometimes, though rare, they wind up in the SPAM folder.

I know the embedding of images helps to avoid this and it also allows the images to remain visible while offline.

Nonetheless, I appreciate the feedback.

Any other ideas? ....anyone else?
Copy linkTweet thisAlerts:
@yamaharussFeb 13.2008 — Google is your friend...


[CODE]Const CdoReferenceTypeName = 1
Dim objCDO, objBP
Set objCDO = Server.CreateObject("CDO.Message")
objCDO.MimeFormatted = True
objCDO.To = "[email protected]"
objCDO.From = "[email protected]"
objCDO.Subject = "Embedded image demo"
objCDO.HTMLBody = "<html>Check this out: <img src=""cid:myimage.gif""></html>"

' Here's the good part, thanks to some little-known members.
' This is a BodyPart object, which represents a new part of the multipart MIME-formatted message.
' Note you can provide an image of ANY name as the source, and the second parameter essentially
' renames it to anything you want. Great for giving sensible names to dynamically-generated images.
Set objBP = objCDO.AddRelatedBodyPart(Server.MapPath("/images/myimage.gif"), "myimage.gif", CdoReferenceTypeName)

' Now assign a MIME Content ID to the image body part.
' This is the key that was so hard to find, which makes it
' work in mail readers like Yahoo webmail & others that don't
' recognise the default way Microsoft adds it's part id's,
' leading to "broken" images in those readers. Note the
' < and > surrounding the arbitrary id string. This is what
' lets you have SRC="cid:myimage.gif" in the IMG tag.
objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<myimage.gif>"
objBP.Fields.Update

objCDO.Send[/CODE]
Copy linkTweet thisAlerts:
@gregw74authorFeb 15.2008 — In my research, previous to my posting this question, I actually came across this example. When applying it, it doesn't appear to work, imagine that. Have you tested it by chance? It was very frustrating because I thought it was going to make for a good solution.

If anyone has tested this code, or has any other suggestions, I'm certainly open to your feedback. Please!
Copy linkTweet thisAlerts:
@yamaharussFeb 15.2008 — yes I tested it. If you want to pass me your email address I will send the test to you.
Copy linkTweet thisAlerts:
@gregw74authorFeb 15.2008 — That would be great. Thank you! I've sent you a PM with my email address.
Copy linkTweet thisAlerts:
@yamaharussFeb 15.2008 — Test message has been sent to you along with full code
Copy linkTweet thisAlerts:
@gregw74authorFeb 18.2008 — Thank you. It's working great now. I think my problem initially was that I was using an absolute URL for the image location. Switching to a relative path, as the comments in the code suggest, seems to have done the trick.

Thanks again for your help! My own small mind and two eyes is never enough sometimes. LOL
Copy linkTweet thisAlerts:
@yamaharussFeb 19.2008 — You're welcome. Glad I could help.
Copy linkTweet thisAlerts:
@staleraJan 16.2009 — Hi,

Can you please send me the project also, since I'm facing the same problem.

Thanks
Copy linkTweet thisAlerts:
@yamaharussJan 17.2009 — The code has been posted. What else do you need?
Copy linkTweet thisAlerts:
@TampaWebDesignOct 27.2009 — Thanks for posting that solution. I had a client ask me about this the other day.

?
Copy linkTweet thisAlerts:
@yamaharussOct 27.2009 — My pleasure.
Copy linkTweet thisAlerts:
@diana_solisFeb 20.2012 — Hi!!!

I have the same problem. Please. can you pass me the test and the code?.
Copy linkTweet thisAlerts:
@yamaharussFeb 21.2012 — Hi!!!

I have the same problem. Please. can you pass me the test and the code?.[/QUOTE]


All the code you need had been posted.
Copy linkTweet thisAlerts:
@MrSpock1734Sep 24.2017 — Hi. I'm new to webDeveloper. Please post me the code for "Embed Images in CDO mail message" as I am having difficulty embedding a logo image to email footer.

I am developing in Visual Foxpro and it does not like:

objCDO.HTMLBody = "<html>Check this out: <img src=""cid:myimage.gif""></html>"

the two sets of double quotes "" are causing problem with Foxpro .

Regards, George
Copy linkTweet thisAlerts:
@rootSep 24.2017 — This is a very old post you have resurected, please post a new thread if you have a problem and not hijack other threads, thanks.

Closing as this is a very old post.
×

Success!

Help @gregw74 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...