Sending email with AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Sending email with AHK

22 Apr 2017, 16:09

I've tried about a dozen scripts I found in various forums but I can't get any to work.

I need one specifically for Gmail but it can be any script that allows you to set the SMTP server, port, sender, receiver, subject/content and include an attachment file.

If you have one handy please enlighten me with your gift!

Thanks.
ahk new

Re: Sending email with AHK

22 Apr 2017, 16:41

Hi

try

Code: Select all

ComObjError(false)   ;disable COM error messages for some non available properties
m := ComObjCreate("Outlook.Application").CreateItem(0)
m.Subject := "Pick List" A_Tab ORDEN A_Tab CONSECU
m.To := "[email protected]"
m.Cc :=  "[email protected]"


fff=C:\picklist\materialistas\test.txt

Body =
(Join

<p>Buen dia...</p>
<p>Se ha creado un nuevo PickList para Almacen,esta es la informacion</p>
<p>ORDEN:		%ORDEN%<br>FOLIO:		%CONSECU%<br>QTY TOTAL ORDEN:		%QTY%<br>Usuario:		%SOLICITANTE%<br>KIT SIZE:		%kitsize%<br>SUB ENSAMBLE:		%SUBENSAMBLE%</p>
<p>Favor de dar seguimiento desde la aplicacion <a href="%fff%">ALMACEN</a></p>



<p>Si usted piensa que no deberia recibir esta informacion favor de comunicarlo a Hot Hot 85<br>Gracias.</p>

;attach pic
<img src="C:\mndisk\Ticket_Requisitor\pic.jpeg" alt="HTML5 Icon" style="width:28px;height:8px;">
 
)

m.HTMLBody := Body
m.Display ;t*o display the email message...and the really cool part, if you leave this line out, it will not show the window............... but the m.send below will still send the email!!!
m.Send ;to *automatically send and CLOSE that new email window...  

I hopé it help
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

23 Apr 2017, 21:59

The first responders code requires outlook which isnt going to be possible. I tried the blat one too with this code and it was unsuccessful.

Code: Select all

SMTPServer                                      := "smtp.gmail.com"
SMTPUsername                                    := "[email protected]"
SMTPPassword                                    := "mypassword"
F      	                                        := "[email protected]"
To    	                                        := "[email protected]"
Subject                                         := "TEST1"
Body                                            := "TEST1"

run, blat -noh2 -serverSMTP %SMTPServer% -u %SMTPUsername% -pw %SMTPPassword% -f %F% -to %To% -subject %Subject% -body %Body%
I get this screen for about a minute:
Capture11.PNG
Capture11.PNG (45.3 KiB) Viewed 14429 times
Then it goes away and no email was sent.

Any ideas?

Thanks for your help.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Sending email with AHK

24 Apr 2017, 06:46

Not sure if this isn't outdated. Make up your mind if AHK could be connected to it:

[How To Send Emails From The Commandline In Windows (Without Extra Software)]
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

24 Apr 2017, 09:02

I've come to the conclusion that Gmail requires SSL and none of these scripts or Blat support SSL.

I've been trying the fix with Stunnel\Blat but also looking into the script with mailsend.

One issue is that the file no longer exists where the script leads to. I downloaded a different version here:
https://github.com/muquit/mailsend/releases

I ran it manually with this command:

mailsend.exe -to "myemail" -from "myemail" -ssl -smtp smtp.gmail.com -port 465 -sub "subject" -M "emailMessage" -q -auth-plain -user "myemail" -pass "mypass" -attach "test.txt",, Hide

And I get this error:
Capture2.PNG
Capture2.PNG (2.33 KiB) Viewed 14385 times
Still working on it, but if you can help let me know.

Thanks.
Treashunter

Re: Sending email with AHK

25 Apr 2017, 15:16

Hey - im a bit late to the party here, but i use this to automatically send emails whenever a user creates a quote for our internal company use.

Works good for me - just fill in with your server info, etc.

Code: Select all

pmsg 							:= ComObjCreate("CDO.Message")
pmsg.From 						:= "[email protected]"
pmsg.To 							:= "[email protected]"
pmsg.BCC 							:= ""   									; Blind Carbon Copy, Invisible for all, same syntax as CC
pmsg.CC 							:= ""										; [email protected], [email protected]
pmsg.Subject 						:= "Subject"
;pmsg.TextBody 					:= ""
pmsg.HtmlBody 					:= "Body"

sAttach   							:= QuotePath								; can add multiple attachments, the delimiter is |
fields 							:= Object()

fields.smtpserver   					:= "smtp server here" 							; specify your SMTP server
fields.smtpserverport   				:= 587									; 25
fields.smtpusessl      					:= False									; False
fields.sendusing     					:= 2   									; cdoSendUsingPort
fields.smtpauthenticate 				:= 1   									; cdoBasic
fields.sendusername 					:= "xxxxxxxxxxxxx"
fields.sendpassword 					:= "xxxxxxxx"
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()
Lemme know if you have questions!

Thanks!
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

25 Apr 2017, 17:38

I get this error. I believe since gmail requires SSL.
Capture2.PNG
Capture2.PNG (39.15 KiB) Viewed 14359 times
Don''t think that will work, unless I'm doing something wrong.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Sending email with AHK

25 Apr 2017, 17:42

Are you able to use another email client like Thunderbird? I just wrote up this very shoddy automatic email composer (doesn't send, because it doesn't use COM or anything, there's a chance of a typo).

Code: Select all

^7::
WinActivate, ahk_exe thunderbird.exe
Send ^n ; new email
WinWaitActive, Write: (no subject)
Sleep 250
Send !r ; gets to the fRom field
Sleep 250
Send {Down 10} ; scrolls to the bottom to prompt the dropdown to appear
Sleep 100
Send {End}{Up} ; selects the bottom option in the dropdown
Sleep 100
Send {Tab 3} ; moves to the To field
SendInput [email protected] ; the person I'm emailing
Sleep 100
Send {Tab} ; moves to the Title field
FormatTime, outputMcD, , MM/dd/yy 
SendInput %outputMcD% ; provides a Title
Sleep 100
Send {Tab} ; Move to the Body
Sleep 100
Send My Name ; populate the Body
return
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

25 Apr 2017, 17:56

Unfortunately Thunderbird is not an option.

Furthermore, I'm really trying to avoid any use of sending commands in that fashion.

I am open to a command based email service like Blat if it uses SSL, Blat doesn't :(
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Sending email with AHK

26 Apr 2017, 05:20

Hi I'm also trying to something similar like you. I have found a PowerShell solution.
This scripts creates email.ps1, runs it and afterwards deletes the .ps1 file.

The only thing I'm personally not happy about is, that the login name / password are stored in
a file, which is a security issue. Even though the file is deleted one second after
execution.

Hope this helps:

Code: Select all

#NoEnv
#Warn
#SingleInstance Force
SetBatchLines, -1
SendMode, Input

FileDelete, email.ps1 

SMTPServer				= "smtp.someprovider.com"
SMTPClient				= New-Object Net.Mail.SmtpClient($SMTPServer, 587)
SMTPClientEnableSsl 	= $true
SMTPClientCredentials 	= New-Object System.Net.NetworkCredential("[email protected]", "SomePassword");

EmailFrom 	= "[email protected]"
EmailTo		= "[email protected]"
Subject 	= "NSA hacktool"
Body 		= "Hi Marc, I'm glad to inform you my NSA hacktool is ready"

FileAppend, $SMTPServer = %SMTPServer%`n, email.ps1
FileAppend, $SMTPClient = %SMTPClient%`n, email.ps1
FileAppend, $SMTPClient.EnableSsl = %SMTPClientEnableSsl%`n, email.ps1
FileAppend, $SMTPClient.Credentials = %SMTPClientCredentials%`n, email.ps1
FileAppend, $EmailFrom = %EmailFrom%`n, email.ps1
FileAppend, $EmailTo = %EmailTo%`n, email.ps1
FileAppend, $Subject = %Subject%`n, email.ps1
FileAppend, $Body = %Body%`n, email.ps1
FileAppend, $SMTPClient.Send($EmailFrom`, $EmailTo`, $Subject`, $Body)`n, email.ps1
run, powershell.exe -ExecutionPolicy Bypass -File email.ps1

Sleep, 1000
FileDelete, email.ps1 
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Sending email with AHK

28 Apr 2017, 14:34

[brainfart]
You probably can save your password (slightly encrypted?) within the compiled scripts metadata or an AlternateDataStream. That way you wouldn't have to create an additional plain text file.
[/brainfart]

https://autohotkey.com/boards/viewtopic.php?t=27909
https://autohotkey.com/board/topic/6500 ... ript-file/
https://autohotkey.com/boards/viewtopic.php?t=5677
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

28 Apr 2017, 17:06

WalkerOfTheDay wrote:Hi I'm also trying to something similar like you. I have found a PowerShell solution.
This scripts creates email.ps1, runs it and afterwards deletes the .ps1 file.
This one isn't working for gmail either. The powershell opens, but it's not actually sending the email.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Sending email with AHK

29 Apr 2017, 08:47

magicinmath wrote:
WalkerOfTheDay wrote:Hi I'm also trying to something similar like you. I have found a PowerShell solution.
This scripts creates email.ps1, runs it and afterwards deletes the .ps1 file.
This one isn't working for gmail either. The powershell opens, but it's not actually sending the email.
I believe I had it working with gmail. What smtp port are you using?
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

29 Apr 2017, 18:28

I've tried all of them available to gmail, but 465 is the recommended.
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Sending email with AHK

01 May 2017, 01:41

magicinmath wrote:I've tried all of them available to gmail, but 465 is the recommended.
For me it works in gmail with port 587.

edit

You might have to turn this on:

https://support.google.com/accounts/ans ... 0255?hl=en

edit2
Yes, above is the problem. When I turn it off, it doesn't work for me neither.
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: Sending email with AHK

01 May 2017, 10:45

Is there anyway to include attachments to the email?
User avatar
WalkerOfTheDay
Posts: 710
Joined: 24 Mar 2016, 03:01

Re: Sending email with AHK

01 May 2017, 12:11

magicinmath wrote:Is there anyway to include attachments to the email?
Yes I think so. Haven't had the time to test it through.

Check below article.

https://social.technet.microsoft.com/Fo ... powershell

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot] and 82 guests