Compose an Outlook Email with an embedded picture
Posted: 13 Feb 2024, 13:25
As I needed it for work here is a short script that creates a new mail in outlook with some HTML text and an embedded picture:
The mail will remain open for you to edit it, but could be sent automatically or saved as a draft (see commented lines at the end).
--- History ---
19th of February 2024:
Replaced property 0x3712001E by 0x3712001F for some edge cases.
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
UniquePictureId := "MyUniquePictureName"
PathToPicture := A_ScriptDir "\P01132.jpg"
olMailItem := 0
o:= ComObjActive("Outlook.Application").Session()
MailItem := ComObjActive("Outlook.Application").CreateItem(olMailItem)
MailItem.TO :="recipient@email.com"
; MailItem.CC :=""
; MailItem.Replyto :="your@email.com"
MailItem.Subject := "New employees"
MailItem.HTMLBody := "<html><body>This is our new employee Thomas:<br><img src='cid:" UniquePictureId "'></body></html>"
attachment := MailItem.Attachments.Add(PathToPicture,1,1,UniquePictureId)
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", UniquePictureId) ;Important - Sets the CID-Tag for the attachment to be able to embed it
MailItem.Display(true)
; MailItem.Close(0) ; Creates a draft
; MailItem.Send() ;Send email
return
--- History ---
19th of February 2024:
Replaced property 0x3712001E by 0x3712001F for some edge cases.