Send an email

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
samking
Posts: 1
Joined: 18 May 2015, 10:14

Send an email

18 May 2015, 10:25

Hello,
I would like make a script with AutoHotkey than send an email to multi-users.
I've seen a lot of examples but that did'nt work for me :(

Here is my script :

Code: Select all

pmsg 			:= ComObjCreate("CDO.Message")
pmsg.From 		:= """AHKUser"" <[email protected]>"
pmsg.To 		:= "myemail"
pmsg.BCC 		:= ""   ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC 		:= "[email protected], [email protected]"
pmsg.Subject 	:= "Message_Subject"

;You can use either Text or HTML body like
pmsg.TextBody 	:= "Message_Body"
;OR
;pmsg.HtmlBody := "<html><head><title>Hello</title></head><body><h2>Hello</h2><p>Testing!</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 ; 
fields.smtpusessl      := True ; False
fields.sendusing     := 2   ; cdoSendUsingPort
fields.smtpauthenticate     := 1   ; cdoBasic
fields.sendusername := "mygmail_username"
fields.sendpassword := "mygmail_password"
fields.smtpconnectiontimeout := 250
schema := "http://schemas.microsoft.com/cdo/configuration/"

pmsg.Send()
The error is :
"The 'SendUsing' configuration value is invalid"
I've made test with my Outlook email and I changed my smtp,user and password settings but there aren't any changes.
I use this smtp to send/mail dayli without any problem.
I have AutoHotkey v 1.1.22.00, if you could help me, thank you ery much :D
User avatar
flyingDman
Posts: 2821
Joined: 29 Sep 2013, 19:01

Re: Send an email

18 May 2015, 17:14

try this: (works here)

Code: Select all

pmsg 						:= ComObjCreate("CDO.Message")
pmsg.From 					:= """John Doe"" <[email protected]>"
pmsg.To 					:= "[email protected], [email protected]"
pmsg.BCC 					:= ""   									; Blind Carbon Copy, Invisible for all, same syntax as CC
pmsg.CC 					:= ""										; [email protected], [email protected]
pmsg.Subject 					:= "See below"
;pmsg.TextBody 					:= ""
pmsg.HtmlBody 					:= "<html><head><title>Hello</title></head><body><table border='1'><tr><td>row 1, cell 1</td><td>row 1, cell 2</td></tr><tr><td>row 2, cell 1</td><td>row 2, cell 2</td></tr></table> </body></html>"
;sAttach   					:= "" 										; 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 				:= "yourpw"
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()
return
14.3 & 1.3.7
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: Send an email

19 May 2015, 04:53

I have this function, that not being an admin on my system I couldn't get Outlook to stop trying to stop it from running for security reasons, but if you don't have outlook then this doesn't do you any good.

Code: Select all

SendMail(ToAddress, MessageSubject, MessageBody, Args="", AttachmentPath="") {
; Args so far are:
; 	Body Type = /bt:[1,2,3]
; 	From = /f:[email protected]
;	Display = /d
; Keep Args separated by spaces
	ol := ComObjCreate("Outlook.Application")
	ns := ol.getNamespace("MAPI")
	ns.logon("","",true,false) ;get default MAPI profile
	newMail := ol.CreateItem(0) ;0 is Outlook constant 'olMailItem' (thanks Sinkfaze)
	If RegExMatch(Args, "/d")
		newMail.Display
	newMail.Subject := MessageSubject
	newMail.Body := MessageBody
	If (RegExMatch(Args, "/bt:\K(\S+)", Format)) ; Process "Args" for a body type argument passed
		newMail.BodyFormat := Round(Format)
	If (StrLen(AttachmentPath))
	{
		MessageAttach := newMail.Attachments
		Loop, Parse, AttachmentPath, `n, %A_Space%%A_Tab%
		{
			If A_Index = 1
				Root := A_LoopField
			Else
				MessageAttach.Add(Root . "\" . A_LoopField)
		}
	}
	; validate the recipient, just in case...
	myRecipient := ns.CreateRecipient(ToAddress)
	myRecipient.Resolve
	If (!myRecipient.Resolved)
		MsgBox "unknown recipient"
	Else
	{
		newMail.Recipients.Add(myRecipient)
		If (RegExMatch(Args, "/F:\K(\S+)", From))
			newMail.Sender := From
		newMail.Send
	}
	Return
}
iPhilip
Posts: 822
Joined: 02 Oct 2013, 12:21

Re: Send an email

08 Sep 2015, 00:12

I posted a solution that uses system.net.mail here.
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
ketchup208
Posts: 2
Joined: 21 Jul 2016, 07:39

Re: Send an email

15 Sep 2016, 07:06

Hello sorry for bringing this up but
how to give sAttach a variable, it works if i give it a static path but do not work if i give the path as variable

the needed code :

Code: Select all

logpath=%A_Desktop%\InstallationLogs(TODELETE).txt

;i tried all of those with no success
sAttach := %logpath%
sAttach := logpath
sAttach = %logpath%
sAttach := "%logpath%"
any help will be appreciated
ketchup208
Posts: 2
Joined: 21 Jul 2016, 07:39

Re: Send an email

15 Sep 2016, 07:44

ok just fixed it by

Code: Select all

sAttach := A_Desktop . "\InstallationLogs(TODELETE).txt"
i will keep it for the records

thanks anyway

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 314 guests