Including Pictures in an Outlook Email

Including Pictures in an Outlook Email

First of all, you are setting the plain text MailItem.Body property.
Secondly, create an attachment and set the PR_ATTACH_CONTENT_ID property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x3712001F") using Attachment.PropertyAccessor.SetProperty.

Your HTML body (MailItem.HTMLBody property) would then need to reference that image attachment through the cid attribute:

<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).

EDIT: sample script (off the top of my head):

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>"

How to embed an image into an Outlook HTML email message?

If a manual step in the process is an option, you can do it like this:

  1. create the HTML automatically or manually as a saved HTML file, with <img> tags that link to locally-saved image files
  2. attach the HTML to an Outlook email using the 'Insert as text' option tucked away under the down-arrow on the "Insert" button when selecting the HTML file as an attachment.

This populates the HTML email with the HTML from the file and embeds all images. I believe this tool uses Base64 encoding to embed the images as described in Sam's email.

Depending on the workflow, this method might be easier than converting images to Base64 yourself.

Note that this method only works in Outlook for Windows, not Outlook for Mac.

How to insert HTML (including images) in an e-mail in Outlook 2016+

The answer is very simple. In a way, it's obvious, but in another way, it's not.

The answer is that each segment of HTML code inserted has to be a complete HTML file, including the <!DOCTYPE>, <HTML> and <body> tags, not just the desired HTML code. The reason this is not obvious is because if you insert multiple code segments, each one has to be a complete HTML file, which is something you would never do when actually writing HTML. I presume that what is happening is that when Outlook detects a valid HTML file being "Inserted as Text", it strips the opening and closing <!DOCTYPE>, <HTML> and <body> tags and then inserts the code that was between them -- as HTML, not as text.

So, the solution I found was that instead of the single line of code shown in the question, I need to "Insert as Text" a file containing:

<!DOCTYPE html>
<html>
<body>
<img src="https://www.lenetek.com/blog/how-to-create-html-emails-in-outlook/images/attach_file.jpg" alt="Random online image">
</body>
</html>

When I insert that as text in my e-mail, I see the image, not the code.

In all the sources I found online that said to use "Insert as Text" to insert HTML in Outlook, none of them said it had to be a complete HTML file instead of just the desired code. So maybe this Q&A will be helpful to someone else, if I'm not the only person who had to scratch my head for a long time before thinking of that.

========================

Added details about using HTML in the e-mail:

As pointed out in the Lenetek article linked in the question, Outlook does not support all HTML tags. In particular, for embedding images, I have found:

When sending from Outlook:
Outlook does not support <figure> and <FigCaption>. I found that an image and caption placed in those tags were rendered inline, just ignoring the tags. For floating to the right margin, I found I was able to get the same results by replacing <figure> with <table> and then placing the image and its caption each inside of <TR><TD>...</TD></TR>.

When receiving in Outlook:
There are differences in how different e-mail clients interpret HTML, which is probably why some e-mails come with a link at the top for viewing the e-mail in one's browser. In particular, I've read that Outlook is not well behaved in this regard. And that was the case with my right-floated image referred to above.

After doing the "Insert as Text" trick, the image appeared correctly at the right margin in the draft e-mail in Outlook, but when it was sent, the CSS style float attribute was ignored and the table appeared by itself at the left margin with no text wrapped around it. I was able to fix this by, in the <table> tag, replacing the style attribute float: right; with the old-fashioned HTML attribute align="right". With that, the image and caption appeared correctly at the right margin when received in Outlook. I have not tested what it looks like in other e-mail clients.

Receiver can't see images in Outlook Email

It sure sounds like you are sending in the RTF format. You need to send an HTML formatted message with with an image added as an attachment and referenced by the HTML body.

Embed picture in outlook mail body excel vba

You need to add the image and hide it. The position 0 will add and hide it.

.Attachments.Add Fname, 1, 0

The 1 is the Outlook Constant olByValue

Once you add the image then you have to use "cid:FILENAME.jpg" as shown below.

Try this

With OutMail
.To = tName
.CC = ""
.BCC = ""
.Subject = STAT.Range("C1").Value
.Attachments.Add Fname, 1, 0
.HTMLBody = "<html><p>Summary of Claim Status.</p>" & _
"<img src=""cid:Claims.jpg""height=520 width=750>"
.Display
End With

Screenshot

Sample Image



Related Topics



Leave a reply



Submit