Reputation: 4632
I use below code to send email using AHK. It works when I use literal strings in subject and message body. But when I try to use %variable%, the resultant email received has blank subject/message body.
Order :=
Order = %Order% `n FAX MESSAGE
Order = %Order% `n
Order = %Order% `n Sent: %DateString% %TimeString%
pmsg := ComObjCreate("CDO.Message")
pmsg.From := """Lens Shapers"" <fax@l******s.com>"
pmsg.To := "k*******[email protected]"
pmsg.BCC := ""
pmsg.CC := ""
pmsg.Subject := "Lenses are Ready" **;THIS SUBJECT IS TRANSMITTED GOOD**
pmsg.TextBody := %Order% **;THIS MESSAGE BODY IS BLANK WHEN EMAIL IS RECEIVED**
sAttach := ""
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 := "k*****f@l******s.com"
fields.sendpassword := "PASSWORD"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
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()
Upvotes: 0
Views: 496
Reputation: 2312
It should work, but when you use a variable in an expression, you don't use the %
's and when you use ":=
" that is an assignment of an expression. So try:
pmsg.TextBody := Order
As that should work. If you also need text elements, you need to use quotes around literals and the dot concatenation:
pmsg.TextBody := "Order: " . Order . "`n`n" ; also follows with 2 new lines
Hth,
Upvotes: 1