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.