Update #3: Emails go out perfectly using port 465 & 25. When I try to use port 587 for GMail, I get the following error:
COM Error Notification :
Function Name: “Send”
ERROR: (0x80040213)
PROG: CDO.Message.1
DESC: The transport failed to connect to the server.
HELP: ,0
Will Continue?
In my case, choosing to continue does not result in sending a successful email. Thanks in advance for any help. I don't think my ISP would block port 587 while they are not blocking 25 & 465. Anyone know of any client side port detectives that will give both incoming & outgoing port status?
---------------------------------------------------------------
Update#2: I'm doing OK with just leaving out the COM_Term() function. For anyone else having the same problem, your script may serve your purpose if you just leave this function out.
---------------------------------------------------------------
UpDate #1: I found out where my script was hanging up. If I place a pause command right before the COM_Term() function, the script doesn't hang up and I can terminate it via the tray icon. When I unpause & resume the script, it is when the COM_Term() function is executing that puts my computer in the state described below. Any suggestions?
---------------------------------------------------------------
After adding CC & BCC objects, my first attempt at using Sean's original code in a function was totally successful. All the emails, with multiple recipients in different categories (To, CC, BCC), went out perfectly.
When I run the script below, I have the following problems:
The AHK tray icon representing this script won't close automatically after the script runs. It remains there indefinitely until I close it via task manager, currently the only practical method of closing it.
I can't invoke right-click options or double-click the tray icon for this script to bring up the native AHK script progress monitor. When I try to run this script again while the icon is still in the tray, I get "Could not close the previous instance of this script. Keep Waiting?"
Everything else on my computer runs fine; as stated before, the emails go out perfectly.
I'm running AHK Version 1.0.48.05 standard; Win XPSP2; ZoneAlarm Security Suite; Latest Rev of COM.ahk for AHK standard; #Include %A_ScriptDir%, #Include COM.ahk, NOT Persistent.
Thank you in advance for any guidance.
Code:
#SingleInstance force
SetTitleMatchMode, 2
;This script uses MS Collaborative Data Object library via COM/DLL calls. Info on CC & BCC can be found in AHK forum CDO COM - Email Delivery--pages 7, etc, and http://msdn.microsoft.com/en-us/library/ms527351.aspx. CC & BCC were easily accomplished by adding the COM_Invoke statements for those objects. Thanks to Sean for the main code body and the Com Library.
sFrom := "*******@gmail.com"
sTo := "*******@gmail.com"
sCC := "*******@gmail.com"
sBCC := "*******@gmail.com"
sSubject := "GNU Public License"
sBody := "Please Read The Attachment"
sAttach := ""
sServer := "smtp.gmail.com" ; specify your SMTP server
nPort := 465 ; 25
bTLS := True ; False
sUsername := "*******"
sPassword := "*******"
nSend := 2 ; cdoSendUsingPort
nAuth := 1 ; cdoBasic
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, "CC", sCC)
COM_Invoke(pmsg, "BCC", sBCC)
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)
pause
COM_Term()
#Include %A_ScriptDir%
#Include COM.ahk