VBA Email Automation - <img src> tag not displaying images on Mac machines

Viewed 38
Dim OutApp As Object
Dim OutMail As Object
Dim fname As String

fname = "C:\Users\urdearboy\Desktop\(VBA)\Mail Send\QR_Code.jpg"

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
        With OutMail
            .SentOnBehalfOfName = "fakeemail@fake.com"
            .to = Target
            .Subject = "Email with QR Code Attachement"
            .Attachments.Add fname, 1, 0
            .HTMLBody = "<font size=3>" _
                        & "Hello " & Application.WorksheetFunction.Proper(Split(Target.Offset(, 2), " ")(0)) & ", " _
                        & "<br><br>" _
                        & "<img src=""cid:QR_Code.jpg""height=100 width=100>" _
                        & "<br><br>" _
                        & "Thanks, <br>" _
                        & "urdearboy"

            .Send

The image (with file path fname) loads fine on Windows Outlook desktop app, web Outlook across Mac & Windows, but the image does not load in Mac Outlook desktop app.

I don't know much about HTML so wondering if there is something wrong with my code or a better way to embed this image so it loads with for both Mac and Windows users?


Note: This is not a 'download image' issue. The users we tested with have Outlook set to download all images, and the ones that don't, end up with the same output once they download the image.

This is how the image renders on Mac Outlook desktop app

enter image description here

1 Answers

You need to set PR_ATTACH_CONTENT_ID MAPI property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x3712001F") on the attachment to the value used in the src attribute. Windows version is more forgiving and also looks at the matching file name attachment when it does not find one with the right content id:

Replace the line

.Attachments.Add fname, 1, 0

with

dim attach As Object
...
set attach = .Attachments.Add(fname)
attach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "QR_Code.jpg")
Related