'add attachment picture into html email body in office 16 / O365
I have been using this code in office 2013:
With OutMail
.Attachments.Add fName
.HTMLBody = .HTMLBody & "<br><B>" & ChartName & :</B><br>" _ & "<img src='" & fName(i) & "' width='800' height='400'><br>" _
.Display
End With
where fName is full path to png file and Chartname is just a headline for the graph.
This has always worked fine but now in office 2016 / O365 this code pastes an empty html table into the outloop email and no graph or picture is visible. Any pointers how to fix this would be appreciated?
Solution 1:[1]
There are errors on your .HTMLBody line. Try this instead:
.HTMLBody = .HTMLBody & "<br><B>" & ChartName & ":</B><br>" & "<img src='" &
fName(i) & "' width='800' height='400'><br>"
I added a quote and removed unneeded _
.
Solution 2:[2]
Create an attachment and set the PR_ATTACH_CONTENT_ID
property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x3712001F"
) using Attachment.PropertyAccessor
.
Your HTML body (MailItem.HTMLBody
property) would then need to reference that image attachment through the cid:
img src="cid:xyz"
where xyz is the value of the PR_ATTACH_CONTENT_ID
property.
Look at an existing message with OutlookSpy (I am its author - click IMessage button).
attachment = mailitem.Attachments.Add("c:\temp\MyPicture.jpg")
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")
mailitem.HTMLBody = "<html><body>Test image <img src=""cid:MyId1""></body></html>"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Brian M Stafford |
Solution 2 |