Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CDO COM - Email Delivery [AHK_L]


  • Please log in to reply
66 replies to this topic
shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
Just creating a new thread for AHK_L users of CDO COM - Email delivery by Sean - all credits to him.

infogulch and sinkfaze modified versions here!

No need to include COM_L.ahk

pmsg 			:= ComObjCreate("CDO.Message")
pmsg.From 		:= """AHKUser"" <...@gmail.com>"
pmsg.To 		:= "anybody@somewhere.com"
pmsg.BCC 		:= ""   ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC 		:= "Somebody@somewhere.com, Other-somebody@somewhere.com"
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 ; 25
fields.smtpusessl      := True ; False
fields.sendusing     := 2   ; cdoSendUsingPort
fields.smtpauthenticate     := 1   ; cdoBasic
fields.sendusername := "...@gmail.com"
fields.sendpassword := "your_password_here"
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()

Edit1: Much shorter code with For-loop
Edit2: CC and BCC, thanks emmanuel d


majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
Thx. Works nice apart from attachment, you have an error there, its used as a field and should be used as a function - pmsg.AddAttachment(A_LoopField)

This can be done much better via creation of email object that will hold all those globals you specified, probably with some shortcuts like AddAttachment("summer2010*.jpg"). I leave to young forces on the forum to implement it (looking at fincs....) :)
Posted Image

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
duh, the attachment part is the only thing i didnt test! :oops:

anyway, thanks for pointing that out!! :)

majkinetor
  • Moderators
  • 4512 posts
  • Last active: Jul 29 2016 12:40 AM
  • Joined: 24 May 2006
It might be good to add it to the showcase:
sAttach   := A_ScriptFullPath

Posted Image

sinkfaze
  • Moderators
  • 6367 posts
  • Last active:
  • Joined: 18 Mar 2008
Both infogulch and myself had already re-written this script to be compatible with AHK_L.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

Both infogulch and myself had already re-written this script to be compatible with AHK_L.


Yes, the whole point of this thread is to find it more easily, so that new users dont have to read whole 11 page threads to find a working example.
And BTW, thanks, i have linked both the posts to the first post of this thread!

  • Guests
  • Last active:
  • Joined: --
Hi shajul,

Thanks the _L version, only thing missing for now is the display name, any idea?

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

Hi shajul,

Thanks the _L version, only thing missing for now is the display name, any idea?


Use this..
pmsg.From       := """AHKUser"" <...@gmail.com>"


Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
I suggest to use just 25 port number.
fields.smtpserverport := 25 ; 465


shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

I suggest to use just 25 port number.

fields.smtpserverport := 25 ; 465


Any special reason, Sean? Port 465 works for me, and also, google's own documentation says to use port 465 here -> http://mail.google.c...en&answer=13287

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
I linked the page in my post.
The port 465 is used for Implicit SSL, however, many well-known SMTP servers do not support it, e.g. live/hotmail. BTW, I believe that the port 587 is common for Explicit SSL, but, CDOSYS produces an error on that port, so, I suggested to use the normal smtp port 25 instead for it.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
Thanks, added it to the first post..

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
You seemed to miss my point. The port 25 can be used with Gmail too.
I have an Email account on the server which supports only Implicit SSL, and my suggestion is that the port 465 better be exclusively reserved for those servers only.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
oh ok. changed it in the first post.

You seemed to miss my point. The port 25 can be used with Gmail too.
I have an Email account on the server which supports only Implicit SSL, and my suggestion is that the port 465 better be exclusively reserved for those servers only.



Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
Thanks for fixing it in a new thread, I wonder why Sean didn't post it on the first page of the original one!

Works great.