 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Tue Jan 13, 2009 8:30 am Post subject: CDO COM - Email Delivery |
|
|
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 Sat Dec 12, 2009 3:07 am; edited 4 times in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7187
|
Posted: Tue Jan 13, 2009 11:51 am Post subject: |
|
|
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 Tue Jan 13, 2009 3:24 pm; edited 1 time in total |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Tue Jan 13, 2009 1:12 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7187
|
Posted: Tue Jan 13, 2009 1:35 pm Post subject: |
|
|
| 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 ) |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Tue Jan 13, 2009 2:03 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7187
|
Posted: Tue Jan 13, 2009 3:31 pm Post subject: |
|
|
Dear Sean,
| Quote: | | Then, it's hard to tell where locates the loophole. |
I was checking ahkuser instead on my account. ( 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!
Regards,  _________________ Suresh Kumar A N |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Tue Jan 13, 2009 3:36 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Tue Jan 13, 2009 11:02 pm Post subject: |
|
|
| SKAN wrote: | I was checking ahkuser instead on my account. ( I need rest, badly! ) | That happens sometimes.
| Quote: | | The mails were sent properly. | Glad to hear that. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Tue Jan 13, 2009 11:04 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1381 Location: The Interwebs
|
Posted: Wed Jan 14, 2009 1:00 am Post subject: |
|
|
| 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! |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Wed Jan 14, 2009 1:34 am Post subject: |
|
|
| 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 |. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2416 Location: Louisville KY USA
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Thu Jan 15, 2009 12:18 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Yetti
Joined: 18 Dec 2008 Posts: 6
|
Posted: Wed Jan 21, 2009 5:30 pm Post subject: |
|
|
| 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() |
It does not work for me Sean
I tested in XP SP3. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2225
|
Posted: Thu Jan 22, 2009 1:09 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|