CDO CID image (1 Viewer)

spinkung

Registered User.
Local time
Today, 23:44
Joined
Dec 4, 2006
Messages
267
All,

I am trying to create an embedded image in a CDO set up mail.

This is what i have....
Code:
Function SendEmail(strFrom As String, _
                    strTo As String, _
                    strSubject As String, _
                    Optional strBody As String = "", _
                    Optional strHTML As String = "", _
                    Optional strCc As String = "", _
                    Optional strBcc As String = "", _
                    Optional strAttach As String = "")
 
 On Error GoTo ErrorHandler

    Dim iMsg As Object
    Dim iConf As Object
    Dim Flds As Object
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    
    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "146.105.64.125"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Update
    End With
    
    
    Dim objImage As Object
    Dim myPic As String
    
        Set objImage = iMsg.AddRelatedBodyPart(GetImagePath & "Computacenter logo mini.gif", "cclogo.gif", [COLOR="Red"]CdoReferenceTypeName[/COLOR])
        objImage.Fields.Item("urn:schemas:mailheader:Content-ID") = "<cclogo.gif>"
        objImage.Fields.Update
        myPic = "<html><img src=""cid:cclogo.gif"" alt=""CC Logo"" /></br></html>"
                 
               
    With iMsg
        Set .Configuration = iConf
        .To = strTo                                         'To
        If strCc <> "" Then .CC = strCc                     'Cc
        If strBcc <> "" Then .BCC = strBcc                  'Bcc
        .FROM = strFrom                                     'From
        .Subject = strSubject                               'Subject
        If strHTML <> "" Then .HTMLBody = myPic & strHTML   'HTML body
        If strBody <> "" Then .TextBody = strBody           'Text body
        If strAttach <> "" Then .AddAttachment strAttach    'Attachment
        .Send
    End With
    
    SendEmail = True

ExitHere:
Exit Function
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
SendEmail = False
Resume ExitHere
    
End Function

... but i keep getting an error message saying variable not defined where the red highlight is?? can anyone help with this/see where i'm going wrong??

Thanks, spin
 

spinkung

Registered User.
Local time
Today, 23:44
Joined
Dec 4, 2006
Messages
267
cracked it..


need tp replace CdoReferenceTypeName with cdoRefTypeId and it seems to have worked.

:)
 

BeBeLu

New member
Local time
Today, 18:44
Joined
Oct 21, 2013
Messages
3
Hello, Thank you, this is great information! I'm using it to send images in email bodies, rather than as attachments. I'm not trying to combine any fields/parts, but it works well to embed images. I hoped to do a bit more with it, and would appreciate any advice!
- I tried to add the background tag, so that the image would display in the background and the text typed into the body would display on top.
- I changed the img parameter to other types (txt, mp4) to see if I could embed them as well. It sent it, however it treats it more like an attachment (possibly because of the body parts?)

Thank you in advance!

Dim objImage As Object
Dim myPic As String
Set objImage = iMsg.AddRelatedBodyPart(GetImagePath & "Computacenter logo mini.gif", "cclogo.gif", CdoReferenceTypeName)
item22 = "<h1>" & strbody & "</h1>"
Set objImage = iMsg.AddRelatedBodyPart(strinclude, item22, cdoRefTypeId)
objImage.Fields.ITEM("urn:schemas:mailheader:Content-ID") = "<" & strinclude & ">"
objImage.Fields.Update
myPic = "<html><img src=""cid:" & strinclude & """ alt=""CC Logo"" /></br></html>"
item22 = "<h1>" & strbody & "</h1><background=" & myPic & "><h1>"
End If
End If
With iMsg
Set .Configuration = iConf
.To = strto 'To
If strcc <> "" Then .cc = strcc 'Cc
If strbcc <> "" Then .bcc = strbcc 'Bcc
.From = strfrom 'From
.Subject = strsubject 'Subject
.HTMLBody = item22
 

Users who are viewing this thread

Top Bottom