send email with variables in subject

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fmildemberger
Posts: 29
Joined: 22 Jan 2014, 10:31

send email with variables in subject

Post by fmildemberger » 06 Dec 2021, 08:18

Hello, I would like to put variables in the body of the email identifying a toner request for a sector, identifying the applicant and the printer model...can someone help me?
Below is the script! but in the email the body only appears what is in quotes, in bold

Code: Select all

inputbox ,setor, Solicitação de toner Laborclin, Digite o setor solicitante:
inputbox ,Nome, Solicitação de toner Laborclin, Digite o nome do solicitante:
inputbox , Impressora ,Solicitação de toner Laborclin , Digite o modelo da impressora:


msgbox, vc digitou %Setor%

pmsg 			:= ComObjCreate("CDO.Message")
pmsg.From 		:= """[email protected]"" <Your gmail address>"
pmsg.To 		:= "[email protected]" ;Sent an email to myself as a test. Perhaps that's why it worked for me.
pmsg.BCC 		:= ""   ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC 		:= ; "[email protected], [email protected]"
pmsg.Subject 	:=  "Solicitação de Toner"

;You can use either Text or HTML body like
pmsg.TextBody 	:= [b]"Solicito toner para o departamento :"[/b] %setor%
;OR
;pmsg.HtmlBody := "<html><head><title>Solicitação de toner</title></head><body><h2>Solicitação de toner</h2><p>Solicito toner para o departamento:</p></body></html>"


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 := "[email protected]"
fields.sendpassword := "zzzzzzzz"
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()
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 06 Dec 2021, 13:17, edited 1 time in total.
Reason: Topic moved from 'Other Utilities & Resources'.

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: send email with variables in subject

Post by Xtra » 06 Dec 2021, 15:01

See: expressions

Basically you are assigning a string (in quotes) and a variable to pmsg.TextBody
When using := strings are quoted and variables are not. The dot between them is not required but clearly show you are concatenating them.

Code: Select all

pmsg.TextBody 	:= "Solicito toner para o departamento : " . setor
HTH

Post Reply

Return to “Ask for Help (v1)”