CDONTS - Embedded images don't show in web-based e-mail

Posted on 2005-03-28
Medium Priority
Last Modified: 2010-07-27
Hello ppl,

I'm using CDONTS to send e-mails with HTML and embedded images. I can use outlook to see the e-mail and see the images, but if i try to open with a web-based e-mail i get a Big red X :(.

What it looks like is that my server is not giving the proper name for the AttachedURL, because i see a file without a name as an attachment in my e-mail.

I can't install other component at my server (i wish i could).

Does anyone have a solution for that?

Thanks a lot.
Question by:guster5k
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2

Expert Comment

ID: 13649741
Hi guster5k,

People often think that when they send an HTML image that has embedded images, that they are actually sending the images with the email. This is incorrect. In fact, you are sending directions in the HTML code, which instructs the recipient where they can find the images.

Most email companies will require that the images for your HTML email message be hosted on your server. And you'll want to make sure that each image is given an "absolute reference." This means you'll need to use the image's whole address because the browser has to locate your site on the web to retrieve the image.

The Wrong Way to Link Images...

The Right Way to Link Images...

The difference between these two images is the first will work only when you view it on your company's website. The "absolute reference" will work when anyone with HTML capabilities who is connected to the web opens it.

If you still getting the error then i think not all the web based email goes not support html based contents. Like rediffmail, gmail etc.

For yahoo it is ok but you have to choose "view html content email" option on.

Hope your probel will be solved.

Thanks and Regards,
Sukamal Sengupta
LVL 10

Expert Comment

ID: 13649783
Attaching them means they have to be opened and used and web based mail doesn't do this unless you specifically open them.

The best way is put external links to your images in the email. This keeps the email size small and doesn't rely on the tricky bit of getting your HTML code to recoginise the attached files esp if it's web based email. When they open the email, the images will load from the web like a webpage.

LVL 10

Expert Comment

ID: 13649807
Yeah! What S.S. said.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

sudheeshthegreat earned 2000 total points
ID: 13651903
problem is you aren't exactly embedding the images. you are just sending a link.
to embed images, use MAPI. here's some code:

      ' Outlook objects
  Dim objApp As Outlook.Application
  Dim l_Msg As Outlook.mailItem
  Dim colAttach As Outlook.Attachments
  Dim l_Attach As Outlook.Attachment
  Dim oSession As MAPI.Session
  ' CDO objects
  Dim oMsg As MAPI.Message
  Dim oAttachs As MAPI.Attachments
  Dim oAttach As MAPI.Attachment
  Dim colFields As MAPI.Fields
  Dim oField As MAPI.Field
  Dim strEntryID As String
  ' create new Outlook MailItem
  Set objApp = CreateObject("Outlook.Application")
  Set l_Msg = objApp.CreateItem(olMailItem)
  l_Msg.BodyFormat = olFormatHTML

  ' add graphic as attachment to Outlook message
  ' change path to graphic as needed
  Set colAttach = l_Msg.Attachments
  Set l_Attach = colAttach.Add(chToPath & "\" & item.Name)
  l_Msg.Close olSave
  strEntryID = l_Msg.EntryID
  Set l_Msg = Nothing
  ' *** POSITION CRITICAL *** you must dereference the
  ' attachment objects before changing their properties
  ' via CDO
  Set colAttach = Nothing
  Set l_Attach = Nothing
  ' initialize CDO session
  On Error Resume Next
  Set oSession = CreateObject("MAPI.Session")
  oSession.Logon "", "", False, False
  ' get the message created earlier
  Set oMsg = oSession.GetMessage(strEntryID)
  ' set properties of the attached graphic that make
  ' it embedded and give it an ID for use in an <IMG> tag
  Set oAttachs = oMsg.Attachments
  Set oAttach = oAttachs.item(1)
  Set colFields = oAttach.Fields
  Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
  Set oField = colFields.Add(&H3712001E, "myident")
  oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
  ' get the Outlook MailItem again
  Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntryID)
  ' add HTML content -- the <IMG> tag
  l_Msg.HTMLBody = "<IMG align=baseline border=0 hspace=0 src=cid:myident>"
  l_Msg.Close (olSave)
    l_Msg.To = "someone@somewhere.com"
    l_Msg.Subject = "imagemail"

Expert Comment

ID: 13658970

Hi sudheeshthegreat,

I think there is no problem in the mail sending code which guster5k use otherwise he could not be able to see it in outlook.

The only problem is viewing the picture.

Sukamal Sengupta

Expert Comment

ID: 13659150
>>The only problem is viewing the picture.
now, why is there a problem? you can either have a link to the image or you can embed the image.
if it is a link, what you (Sukamal_Sengupta) pointed out is correct. it should be an absolute URL.
but, if it is embedding an image, simply putting html with image tags won't do. if you have a look at the html source of mails where the image is embedded, you can see a CID (Content ID) created instead of a link and the above code I wrote is the way to get it.

please note that embedding images in mail would increase the mail-size to include the size of the image. but, if it is just a link to the image, it is as good as simple html.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question