Tut: How to add embedded images in CDO mail

Discussion in 'Microsoft Development' started by antic, Jun 13, 2006.

  1. dalin

    dalin Guppy

    thanks...

    the main reason i went looking for a means to embed images, was to avoid that terrible (red x) where my images SHOULD have been in the email message... it just seems too unprofessional to have what appears to be a "broken" message (to my clients)...

    having said that, im certainly open to other means of getting images into my messages... i just find it to be a much more pleasing experience (myself) when i open email from reputable sources, and find a nicely crafted message (from vendors like TigerDirect, or online services like WoW, etc.)...
  2. khadem1386

    khadem1386 Guppy

    thank for your code.
    I is work very good
    I Haven't any problem in Outlook.

    but My embbede images is failed In yahoo, aol ,hotmail.
  3. khadem1386

    khadem1386 Guppy

    Hi to all

    I check This code succesfully to OUTLOOK Reciever.

    but is Yahoo or aol or Hotmail Reciever. it don't word.
    and dont embbed.

    do you check it to non pop3 Email Reciver?

    Thanks
  4. jawedsoft

    jawedsoft Guppy

    hi group,
    thanks for the wonderful code example. I was looking for this for quite a long time...but unfortunately whatever code I could come up with, did not work with all the mail clients.
    I have tested the above given code example and it works flawlessly on the following email clients.
    a)outlook b)pegasus mail c) lotus note d)gmail e)yahoo

    I had a further requirement that I wanted to embed two images in one mail.(the example shows embedding only one)

    as suggested by the orginal author, we need to create one more object of add relatedbodypart like this
    Code:
    ---------
    Set objBP2 = objCDO.AddRelatedBodyPart(Server.MapPath("/images/myimage2.gif"), "myimage2.gif", CdoReferenceTypeName)
    objBP2.Fields.Item("urn:schemas:mailheader:Content-ID") = "<myimage2.gif>"
    objBP2.Fields.Update
    ---------

    however I tried a different method, instead of creating objBP1 and objBP2 I used the same but in between I wrote objBP.Fields.Update. Now its working for me.
    my code:
    ----------------------------------------------------
    Set objBP = objCDO.AddRelatedBodyPart("c:\birthday\cake4.jpg", "cake.jpg", CdoReferenceTypeName)
    objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<cake.jpg>"
    objBP.Fields.Update
    Set objBP = objCDO.AddRelatedBodyPart("c:\birthday\logo.jpg", "logo.jpg", CdoReferenceTypeName)
    objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<logo.jpg>"
    objBP.Fields.Update
    -----------------------------------------------------


    once again thanks for the code...it works like a charm ! ! !

    Jawed
  5. antic

    antic Perch

    Hi adhunna, it works exactly the same as my original post, read it carefully. There are a few errors in your code so it won't work as you have it. The following code works fine for me.

    Code:
    <%
    dim cdoMessage, cdoConfig, sch
    
    sch = "http://schemas.microsoft.com/cdo/configuration/"
    Set cdoConfig = Server.CreateObject("CDO.Configuration")
    set cdoMessage = Server.CreateObject("CDO.Message")
    
    With cdoConfig.Fields
      .Item(sch & "sendusing") = 2 ' cdoSendUsingPort
      .Item(sch & "smtpserver") = "<your SMTP server>"
      .Item(sch & "sendusername") = "<SMTP username>"
      .Item(sch & "sendpassword") = "<SMTP password>"
      .update
    End With
    
    Set cdoMessage.Configuration = cdoConfig
    cdoMessage.From = "test@test.com"
    cdoMessage.ReplyTo = "test@test.com"
    cdoMessage.To = "<your test email address>"
    cdoMessage.Subject = "Test subject"
    cdoMessage.HtmlBody = "<html><body><img src=""cid:myimage.gif""/></body></html>" & vbCrLf
    
    Set objBP = cdoMessage.AddRelatedBodyPart("http://localhost/integral/survey/images/tpl5/head-logo.gif", "myimage.gif", CdoReferenceTypeName)
    objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<myimage.gif>"
    objBP.Fields.Update
    
    cdoMessage.Send
    
    %>
    Done.
    

Share This Page

JodoHost - 26,000 hosting end-users in 100 countries
Plesk Web Hosting
VPS Hosting
H-Sphere Web Hosting
Other Services