Outlook COM Create email & capture email send

Post your working scripts, libraries and tools for AHK v1.1 and older
Stavencross
Posts: 90
Joined: 24 May 2016, 16:42

Outlook COM Create email & capture email send

Post by Stavencross » 11 Sep 2021, 15:56

Wanted to share an example here of a couple things.
  • create an email and see the on email send event
  • create a copy of an email that is being sent
use case for this is you can create an email for your users, let them modify it, and when they send it, you clone it, so you can 'forward' it else where.
I.E, for my example, I'm trying to send the same customized email to multiple salesforce cases, so I need to capture the customized email, and change the subject a bit each time

Watch out! the 'global Email' is important. If you don't create that, you won't have access to the email you just created from the _Send event, so you won't be able to see subject / body / ect.

Code: Select all

ol := ComObjCreate("Outlook.Application")
global Email
ns := ol.getNamespace("MAPI")
ns.logon("","",true,false)		
Email := ol.CreateItem(0) ;0 is the constant to create a mailItem
emailBody:="Lorem ipsum dolor sit amet, consectetur adipiscing elit"
emailSubject:="my first subject"
emailSubject2:="my second subject"
toAddress:="[email protected]"

olFormatHTML := 2 ;2 is the constant for HTML
Email.BodyFormat := olFormatHTML
Email.Subject := emailSubject
Email.HTMLBody := emailBody ;assign our HTML body
Email.To:=toAddress
Email.Display

ComObjConnect(Email,"Email_")
Email_Send(Cancel) {
	secondMail := Email.Copy
	secondMail.Display
}

Return to “Scripts and Functions (v1)”