• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

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

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.
0
guster5k
Asked:
guster5k
  • 2
  • 2
  • 2
1 Solution
 
Sukamal_SenguptaCommented:
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...
-------------------------------------------------
/images/picture.jpg

The Right Way to Link Images...
--------------------------------------------------
http://www.test.com/images/picture.jpg

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
0
 
slamhoundCommented:
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.

0
 
slamhoundCommented:
Yeah! What S.S. said.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sudheeshthegreatCommented:
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
  oMsg.Update
 
  ' 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"
    l_Msg.Send
0
 
Sukamal_SenguptaCommented:

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.

Thanks,
Sukamal Sengupta
0
 
sudheeshthegreatCommented:
>>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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now