none
Unable to find link to embebbed image in HTMLBoday RRS feed

  • Question

  • My addin saves embedded images in an email in order to be able to print them again after the email has been re-formatted. The HTML line that contains the link to the image is re-written so that it points to the saved image.

    This works fine but I have just come across a case where it did not.
    The only line in the message HTMLBody that contained a link was:

    <img height="89" width="300" apple-inline="yes" id="C1F274FA-DC97-4AD8-8AA5-336F3A935234" apple-width="yes" apple-height="yes" src="cid:0315E2B1-EEB0-4E04-B634-4512E6B466FB@lan" class="">

    but the only embedded attachment had the file name SS-Logo-Sig.gif so my code can not make a link between the two. I would normally expect  "cid:" to be followed by the filename of the image.

    The email has clearly been formatted on an Apple machine at some point in its journey.

    Can anyone explain how to link the image's src with the attachment. In this particular case it would be possible to marry up the link with the file because there is only one but if I got a message with more than on link configured in this way then I would be in trouble.

    Any ideas?

    Mike VE

    Tuesday, January 12, 2016 10:12 AM

Answers

  • Hi,

    take a look of that

    Sub Embedded_Active_item()
        Dim oItem As Object
        Set oItem = ActiveInspector.CurrentItem
    
        Dim pa As Outlook.PropertyAccessor
        Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
        For Each att In oItem.Attachments
        Set pa = att.PropertyAccessor
        MsgBox pa.GetProperty(PR_ATTACH_CONTENT_ID) & vbCr & att.fileName
        Next att
        
    
    End Sub



    Have a nice day. Oliv-

    • Marked as answer by Mike VE Thursday, January 14, 2016 12:51 PM
    Wednesday, January 13, 2016 5:07 PM

All replies

  • Hi Mike,

    Is the image shown in the message?

    Tuesday, January 12, 2016 10:21 PM
  • >>>Can anyone explain how to link the image's src with the attachment.

    According to your description, if you don't care about the message showing an attachment icon or the image not being visible to the sender, you can use code like this snippet to use the name of the attachment, which Outlook will automatically use for the cid value:

    Set objMail = Application.CreateItem(olMailItem)
    objMail.Attachments.Add "D:\pictest.jpg"
    objMail.HTMLBody = "<html><p>This is a picture.</p>" & _
                       "<img src='cid:pictest.jpg' height=480 width=360>"
    objMail.Display

    Wednesday, January 13, 2016 1:53 AM
  • Yes, Eugene, the image appears in the message as part of a signature block.

    David, that technique would work as a one-off but I want to guard against similar situations in the future. There seems to be no mention of the attachment filename (SS-Logo-Sig.gif) in the HTMLBody. The element quoted in my first post is in the right place in the message to be showing the image in the message but how on earth is it making the link between that attachment and the "src=" element? 


    Mike VE

    Wednesday, January 13, 2016 9:13 AM
  • Hi,

    take a look of that

    Sub Embedded_Active_item()
        Dim oItem As Object
        Set oItem = ActiveInspector.CurrentItem
    
        Dim pa As Outlook.PropertyAccessor
        Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
        For Each att In oItem.Attachments
        Set pa = att.PropertyAccessor
        MsgBox pa.GetProperty(PR_ATTACH_CONTENT_ID) & vbCr & att.fileName
        Next att
        
    
    End Sub



    Have a nice day. Oliv-

    • Marked as answer by Mike VE Thursday, January 14, 2016 12:51 PM
    Wednesday, January 13, 2016 5:07 PM
  • Hi, Mike VE

    Do you use undocumented MAPI properties and CDO to add an embedded image file to a message and set the CID so that an HTMLBody property <img> tag can set that image as the source?

    Thursday, January 14, 2016 9:16 AM
  • That's just what I needed. Thanks Oliv

    Mike VE

    Thursday, January 14, 2016 12:52 PM