Click to See Complete Forum and Search --> : Embed Images in CDO mail message


gregw74
02-13-2008, 02:40 PM
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

Sorehead
02-13-2008, 03:19 PM
Just host the images externally and give the src a url to access the image.

yamaharuss
02-13-2008, 04:12 PM
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:\inetpub\mailroot\pickup"
Flds.Update

Set iMsg.Configuration = iConf
iMsg.To = "someone@email.com"
iMsg.From = "email@domain.com"
iMsg.Subject = "Hello World"
iMsg.HTMLBody = "Here is my image <img src="http://www.mysite.com/images/image.jpg">"
iMsg.Send

gregw74
02-13-2008, 04:36 PM
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?

yamaharuss
02-13-2008, 04:40 PM
Google is your friend...


Const CdoReferenceTypeName = 1
Dim objCDO, objBP
Set objCDO = Server.CreateObject("CDO.Message")
objCDO.MimeFormatted = True
objCDO.To = "you@yourdomain.com"
objCDO.From = "you@yourdomain.com"
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

gregw74
02-15-2008, 08:37 AM
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!

yamaharuss
02-15-2008, 08:56 AM
yes I tested it. If you want to pass me your email address I will send the test to you.

gregw74
02-15-2008, 10:37 AM
That would be great. Thank you! I've sent you a PM with my email address.

yamaharuss
02-15-2008, 10:49 AM
Test message has been sent to you along with full code

gregw74
02-18-2008, 01:22 PM
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

yamaharuss
02-18-2008, 06:09 PM
You're welcome. Glad I could help.

stalera
01-16-2009, 05:07 PM
Hi,
Can you please send me the project also, since I'm facing the same problem.

Thanks

yamaharuss
01-16-2009, 10:07 PM
The code has been posted. What else do you need?

TampaWebDesign
10-26-2009, 07:15 PM
Thanks for posting that solution. I had a client ask me about this the other day.
:)

yamaharuss
10-27-2009, 06:29 AM
My pleasure.

diana.solis
02-20-2012, 05:37 PM
Hi!!!
I have the same problem. Please. can you pass me the test and the code?.

yamaharuss
02-21-2012, 05:12 AM
Hi!!!
I have the same problem. Please. can you pass me the test and the code?.

All the code you need had been posted.