Automating an HTML Outlook email with AutoHotKey

Outlook email

HTML Outlook emailAutoHotkey Merchandise-White Stress ball

With AutoHotKey it is very easy to automate an HTML Outlook email!  In the script below I show how to populate some of the common parameters of the object and insert HTML to the body as well as passing in a variable with time.  You can easily tweak the settings to your needs.

#SingleInstance, Force 
Browser_Back:: ;hotkey for running below
olMailItem := 0
o:= ComObjActive("Outlook.Application").Session()
MailItem := ComObjActive("Outlook.Application").CreateItem(olMailItem)
MailItem.BodyFormat := 2 ; olFormatHTML
MailItem.TO :="[email protected];[email protected]"
;~ MailItem.CC :=""
;~ MailItem.Replyto :="[email protected]"

TodayDate := A_DDDD . ", " . A_MMM . " " . A_DD . ", " . A_YYYY ;storing pretty version of date
MailItem.Subject := "email on " TodayDate ;Subject line of email

;***********html body of Outlook email******************* 
MailItem.HTMLBody := "
<H2 style='BACKGROUND-COLOR: red'><br></H2>
<HTML>Your file is here on "(TodayDate)" <br><br>
<span style='color:black'>Please let me know if you have any questions.
<br><br><a href='mailto:[email protected]'>Joe Glines</a> 
;~ MailItem.Attachments.Add(NewFile)

;~ MailItem.Display ;Make email visible
;~ mailItem.Close(0) ;Creates draft version in default folder
MailItem.Send() ;Sends the email

Here is a video walking through the usage of the above script.

Comments are closed.