Can't get my variables right to send email with AHK

Get help with using AutoHotkey and its commands and hotkeys
neil_brumback97
Posts: 4
Joined: 22 May 2020, 11:03

Can't get my variables right to send email with AHK

22 May 2020, 11:13

I'm trying to send email with AHK and I can't get my variables to pass into the email.

Such as getting my ticket number to go into the subject line

%strTicket%

email.Subject := "Logical Access has reviewed your ticket # %strTicket%"

[Mod edit: added missing subject line]
User avatar
Chunjee
Posts: 516
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re:

22 May 2020, 11:18

I believe that would be:
email.Subject := "Logical Access has reviewed your ticket # " strTicket

https://www.autohotkey.com/docs/commands/SetExpression.htm
neil_brumback97
Posts: 4
Joined: 22 May 2020, 11:03

Re:

22 May 2020, 14:55

works great. Now how do I get it to work in the HTML body of the message?

<p>Logical Access has reviewed your ticket # %strTicket%</p>
User avatar
Chunjee
Posts: 516
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re:

22 May 2020, 15:17

I don't understand the question.

Code: Select all

var := "<p>Logical Access has reviewed your ticket # " strTicket "</p>"
maybe?
BoBo
Posts: 3028
Joined: 13 May 2014, 17:15

Re: Re:

22 May 2020, 15:39

neil_brumback97 wrote:
22 May 2020, 14:55
works great. Now how do I get it to work in the HTML body of the message?
You should provide the whole script so people can see your request within its context.
neil_brumback97
Posts: 4
Joined: 22 May 2020, 11:03

Re: Can't get my variables right to send email with AHK

22 May 2020, 16:16

When I insert that line i get a error regarding my quotes located at "<HTML><BODY>.

Trying to get my variables such as %strTicket% to pass into the body of the email.

Here is all my code.

Code: Select all

Outlook := ComObjActive("Outlook.Application")
email := Outlook.Application.CreateItem(0)
email.To := "h150586"
Email.SentOnBehalfOfName := "[email protected]"
email.BCC := "[email protected]"
email.Subject := "Logical Access has reviewed your ticket # " strTicket
email.HTMLBody := "<HTML><BODY>
<p>Logical Access has reviewed your ticket # %strTicket%</p>
<p>Secure Folder Access request for %strUName% has been completed successfully</p>
<ln>Secure Folder:	%strSharePath%</ln><br>
<ln>User Name:		%strUID%</ln><br>
<ln>Type of Access:	%strAccLvl%</ln><br>
<ln>Group Name:		%strGroup%</ln>
<ln>ACTIONS:</ln>
<li>A reboot of your computer is required for access.</li>
<li>Allow up to 24 hours for permissions to replicate.</li></p>
<p>HAVE QUESTIONS? Please contact me at [email protected]</p>
<p>Regards,</p>
<ln>myCompany Logical Access Governance</ln>
</BODY></HTML>"
email.Send()
[Mod edit: added code-tags, changed user details for privacy/company policy reasons]
neil_brumback97
Posts: 4
Joined: 22 May 2020, 11:03

Re: Can't get my variables right to send email with AHK

22 May 2020, 16:46

Think I got it those " are tricky

<p>has reviewed your ticket # " strTicket "</p>

Thanks!
BoBo
Posts: 3028
Joined: 13 May 2014, 17:15

Re: Can't get my variables right to send email with AHK

22 May 2020, 18:44

Creating a template that contains dynamic stuff is a beast. Especially if used with expressions. Using the Format-command offers an option ...

Code: Select all

array := {1:"0815",2:"JB",3:"\\UNC\path",4:4711,5:8,6:"orks",7:"[email protected]"} ; variables kept in an array to make them accessible within the template

HTMLB := Format(" ; method that will allow us to fill the template with dynamic/variable content from an array
(LTrim
	<HTML><BODY>
	<p>Logical Access has reviewed your ticket # {1}</p>
	<p>Secure Folder Access request for {2} has been completed successfully</p>
	<ln>Secure Folder:{3}</ln><br>
	<ln>User Name:{4}</ln><br>
	<ln>Type of Access:{5}</ln><br>
	<ln>Group Name:{6}</ln>
	<ln>ACTIONS:</ln>
	<li>A reboot of your computer is required for access.</li>
	<li>Allow up to 24 hours for permissions to replicate.</li></p>
	<p>HAVE QUESTIONS? Please contact me at {7}</p>
	<p>Regards,</p>
	<ln>myCompany Logical Access Governance</ln>
	</BODY></HTML>
)", array*)

MsgBox % HTMLB ; for testing
email.HTMLBody := HTMLB
... and btw, I'd use frameless tables to adjust the layout of your text.
User avatar
Chunjee
Posts: 516
Joined: 18 Apr 2014, 19:05
GitHub: Chunjee

Re: Can't get my variables right to send email with AHK

22 May 2020, 19:07

neil_brumback97 wrote:
22 May 2020, 16:16
When I insert that line i get a error regarding my quotes located at "<HTML><BODY>.
That error is trying to tell you it doesn't understand the line. ahk doesn't immediately understand that your string from the line line above hasn't ended yet.

There are a few ways to make multi-line strings, (LTrim is one.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], JackMa and 289 guests