AutoHotkey Community

It is currently May 26th, 2012, 2:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 199 posts ]  Go to page 1, 2, 3, 4, 5 ... 14  Next
Author Message
 Post subject: CDO COM - Email Delivery
PostPosted: January 13th, 2009, 8:30 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
In this script, Email is sent using GMail SMTP (SSL) server.

NEED: COM Standard Library.

Code:
sFrom     := "Mail_Address_Of_Sender"
sTo       := "Mail_Address_Of_Receipient"
sSubject  := "Message_Subject"
sBody     := "Message_Text"
sAttach   := "Path_Of_Attachment" ; can add multiple attachments, the delimiter is |

sServer   := "smtp.gmail.com" ; specify your SMTP server
nPort     := 465 ; 25
bTLS      := True ; False
nSend     := 2   ; cdoSendUsingPort
nAuth     := 1   ; cdoBasic
sUsername := "your_username"
sPassword := "your_password"

COM_Init()
pmsg :=   COM_CreateObject("CDO.Message")
pcfg :=   COM_Invoke(pmsg, "Configuration")
pfld :=   COM_Invoke(pcfg, "Fields")

COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendusing", nSend)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserver", sServer)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", nPort)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpusessl", bTLS)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", nAuth)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendusername", sUsername)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendpassword", sPassword)
COM_Invoke(pfld, "Update")

COM_Invoke(pmsg, "From", sFrom)
COM_Invoke(pmsg, "To", sTo)
COM_Invoke(pmsg, "Subject", sSubject)
COM_Invoke(pmsg, "TextBody", sBody)
Loop, Parse, sAttach, |, %A_Space%%A_Tab%
COM_Invoke(pmsg, "AddAttachment", A_LoopField)
COM_Invoke(pmsg, "Send")

COM_Release(pfld)
COM_Release(pcfg)
COM_Release(pmsg)
COM_Term()


Last edited by Sean on December 12th, 2009, 3:07 am, edited 4 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 11:51 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
It does not work for me Sean :(
Edit: Sorry! the following script works flawlessly.
I am posting the exact script with valid email-id's / username and password:

Code:
StringReplace, Attachment, A_AhkPath, AutoHotkey.exe, License.txt

sFrom     := "ahkuser@gmail.com"
sTo       := "arian.suresh@gmail.com"
sSubject  := "GNU Public License"
sText     := "Please Read The Attachment"
sAttach   := Attachment

sServer   := "smtp.gmail.com" ; specify your SMTP server
nPort     := 465 ; 25
bTLS      := True ; False
sUsername := "ahkuser"
sPassword := "ahkuser1"

COM_Init()
pmsg :=   COM_CreateObject("CDO.Message")
pcfg :=   COM_Invoke(pmsg, "Configuration")
pfld :=   COM_Invoke(pcfg, "Fields")

COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserver", sServer)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", nPort)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpusessl", bTLS)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendusername", sUsername)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendpassword", sPassword)
COM_Invoke(pfld, "Update")

COM_Invoke(pmsg, "From", sFrom)
COM_Invoke(pmsg, "To", sTo)
COM_Invoke(pmsg, "Subject", sSubject)
COM_Invoke(pmsg, "TextBody", sText)
COM_Invoke(pmsg, "AddAttachment", sAttach)
COM_Invoke(pmsg, "Send")

COM_Release(pfld)
COM_Release(pcfg)
COM_Release(pmsg)
COM_Term()


I updated my copy of COM in UserLib. The TrayIcon is seen for a few seconds. But no joy in my inbox.

What Am I missing?


Last edited by SKAN on January 13th, 2009, 3:24 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 1:12 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
SKAN wrote:
It does not work for me Sean :(

Was there no error message? It usually produces an error at the stage of the function Send if fails. Anyway, I suspect it's the attachment. GMail doesn't allow an executable file as an attachment, changing the file name doesn't work either, at least with me. So, I myself always compress/zip it, then send. I suggest to try the same.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 1:35 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Sean wrote:
Was there no error message? It usually produces an error at the stage of the function Send if fails.


No error at all. It takes the usual few seconds like with blat... only that blat cannot handle gmail and hence I want this script verryy much.

Quote:
Anyway, I suspect it's the attachment. GMail doesn't allow an executable file as an attachment, changing the file name doesn't work either, at least with me. So, I myself always compress/zip it, then send. I suggest to try the same.


I am attaching only a text file. Iam using StringReplace to derive the path to the following text file:
C:\Program Files\AutoHotkey\License.txt

Please help. I would love to use GMail programmatically.. ( So would many )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 2:03 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
SKAN wrote:
No error at all.

Then, it's hard to tell where locates the loophole. What's the OS btw? The only suggestion I can think of atm is changing the port number from 465 to 587. In fact, 587 is my preferred port with GMail, however, didn't work in my XPSP3 so used 465 instead. And, although it's unlikely, may use full account name as the username.
Code:
ahkuser@gmail.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 3:31 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Sean, :)

Quote:
Then, it's hard to tell where locates the loophole.


I was checking ahkuser instead on my account. :oops: ( I need rest, badly! )
The mails were sent properly. Very sorry for the inconvenience.

I tested in XP SP2.

I cannot thank you enough for this, Sean. I've been searching for such a solution over 2 years. Thank you SOoo much! :D

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 3:36 pm 
Excellent indeed!

One question though: what are the links in the code for?
Quote:
http://schemas.microsoft.com/cdo/configuration/sendusing


They all lead to 404 error pages.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 11:02 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
SKAN wrote:
I was checking ahkuser instead on my account. :oops: ( I need rest, badly! )
That happens sometimes.
Quote:
The mails were sent properly.
Glad to hear that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 13th, 2009, 11:04 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
n-l-i-d wrote:
One question though: what are the links in the code for?
Quote:
http://schemas.microsoft.com/cdo/configuration/sendusing
That's just the way they locate the fields, i.e., namespace.
http://msdn.microsoft.com/en-us/library/ms527274.aspx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 1:00 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Wow Sean, very nice. I have seen many requests for AHK code to send email without external apps, and here we have one that can even handle gmail, unlike blat. Great work!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 1:34 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Krogdor wrote:
Wow Sean, very nice. I have seen many requests for AHK code to send email without external apps, and here we have one that can even handle gmail, unlike blat. Great work!

Thanks. I forgot to update the script to allow multiple attachments, so done it now. The delimiter is |.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 14th, 2009, 3:45 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
exchange?
instead of smtp would i use my exchange server im a bit dense on mail protocols

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 15th, 2009, 12:18 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
tank wrote:
exchange?
instead of smtp would i use my exchange server im a bit dense on mail protocols

I don't think cdosys.dll defaultly installed on W2K higher supports using exchange. But if cdoex.dll is installed in your system, you can use exchange via cdoSendUsingExchange.
http://msdn.microsoft.com/en-us/library/aa579557.aspx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 21st, 2009, 5:30 pm 
Offline

Joined: December 18th, 2008, 9:25 am
Posts: 6
Code:
#include COM.ahk

sFrom     := "vasy@list.ru"
sTo       := "vasy@list.ru"
sSubject  := "GNU Public License"
sText     := "Please Read The Attachment"
sAttach   := "C:\License.zip"

sServer   := "smtp.list.ru" ; specify your SMTP server
nPort     := 2525 ; 25
bTLS      := True ; False
sUsername := "vasy@list.ru"
sPassword := "*******"

COM_Init()
pmsg :=   COM_CreateObject("CDO.Message")
pcfg :=   COM_Invoke(pmsg, "Configuration")
pfld :=   COM_Invoke(pcfg, "Fields")

COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendusing", 2)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 60)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserver", sServer)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpserverport", nPort)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpusessl", bTLS)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendusername", sUsername)
COM_Invoke(pfld, "Item", "http://schemas.microsoft.com/cdo/configuration/sendpassword", sPassword)
COM_Invoke(pfld, "Update")

COM_Invoke(pmsg, "From", sFrom)
COM_Invoke(pmsg, "To", sTo)
COM_Invoke(pmsg, "Subject", sSubject)
COM_Invoke(pmsg, "TextBody", sText)
COM_Invoke(pmsg, "AddAttachment", sAttach)
COM_Invoke(pmsg, "Send")

COM_Release(pfld)
COM_Release(pcfg)
COM_Release(pmsg)
COM_Term()

Image
It does not work for me Sean :(
I tested in XP SP3.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2009, 1:09 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Yetti wrote:
It does not work for me Sean :(
I tested in XP SP3.

I'm on XPSP3 too. Anyway, the cdo error code is
Code:
CDO_E_FAILED_TO_CONNECT := 0x80040213

So it seems to be your network connection problem. How big is your attachment? I suggest to test first without an attachement.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 199 posts ]  Go to page 1, 2, 3, 4, 5 ... 14  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group