You can use it to add direct e-mailing to any of your scripts—no e-mail client program required. I take no credit for writing the script. I only post it here because I find the technique important enough to deserve a reposting:
Code: Select all
pmsg := ComObjCreate("CDO.Message") ; Do not change
pmsg.From := """Mr Big"" <mrbig@gmail.com>"
pmsg.To := "mrsmall@gmail.com"
pmsg.BCC := "" ; Blind Carbon Copy, Invisible for all, same syntax as CC
pmsg.CC := ""
pmsg.Subject := "E-mail Test"
pmsg.TextBody := "Test of sending e-mail directly from AutoHotkey."
; Remove semicolon to activate attachment feature
; sAttach := ; "Path_Of_Attachment" ; can add multiple attachments
; the delimiter is |
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "mrbig@gmail.com"
fields.sendpassword := "password"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/" ; Do not change
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
pmsg.AddAttachment(A_LoopField)
pmsg.Send()
I've added the EmailSend.ahk script to my AutoHotkey scripts page.
This script acts as a template for sending e-mail directly from AutoHotkey. You must tailor the code to your own e-mail server, username, password, recipient name and other pertinent data.
Many AutoHotkey scripts merely open the default Windows e-mail program (MailTo:) while inserting the appropriate parameters. This AutoHotkey script bypasses any e-mail programs and directly sends the message using ComObject.
It worked for me and has shown itself to be reliable when run by Window Schedule to deliver a daily horoscope scraped from a Web page (image above). I discuss that horoscope mailing script in "E-mail the Daily Horoscope to Yourself."