Create an Email with embedded Picture
Now we create one email with a Picture in the body. This is done by adding the picture as an attachment and embedding it in the body; as a start we take the code from the example EmailDemo, and adapt it.
1. To add the attachments place the code Set att = .Attachments.Add(strPicPath, 1, 0)
as shown below. The position 1 means olByValue
,
the attachment is a copy of the original file and can be accessed even if the original file is removed. The position 0 will add the attachment and hide it as attachment.
2.To make the image visible in the body, change the img source
in the
.HTMLBody.
Sub EmailDemo()
Dim strEmailAddress As String
Dim strFirstName As String
Dim strLastName As String
Dim appOutlook As Outlook.Application: Set appOutlook = New Outlook.Application
strEmailAddress = "t.axen@rivm.nl"
' strFirstName = "Thomas"
' strLastName = "Axen"
Dim mimEmail As Outlook.MailItem
Dim strPicPath As String
strPicPath = "C:\temp\carousius.jpg"
Set mimEmail = appOutlook.CreateItem(olMailItem)
With mimEmail
.To = strEmailAddress
.Subject = "Taskforce meeting"
Dim att As Outlook.Attachment
Set att = .Attachments.Add(strPicPath, 1, 0) ' set the attachment and hide it
.HTMLBody = "<html><h2>Reminder</h2><p>Lorem ipsum dolor sit amet....</p>" & _
"<img src=""carousius.jpg""></html>"
.Display
End With
End Sub