Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines, -1
sendList = c:\temp\sendList.txt
FileDelete, %sendList%
Time := A_Now
;lastAccessed -= 1, D
EnvAdd, Time, -5, Days
loop, C:\Auto Emailer\*.*, 0, 1
{
if (A_LoopFileTimeModified > Time)
if A_LoopFileExt contains doc,txt,jpg
FileAppend, %A_LoopFileLongPath%`n, %sendList%
}
loop, read, %sendList%
{
ifexist, %A_LoopReadLine%
{
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
splitpath, A_loopreadline, doc
title = File: %doc%
content = Update: %A_LoopReadLine%
sFrom := "[email protected]"
sTo := "[email protected]"
sSubject := title
sBody := content
sAttach := A_LoopReadLine
sServer := "server.example.com" ; specify your SMTP server
nPort := 465
bTLS := False
nSend := 2 ; cdoSendUsingPort
nAuth := 1 ; cdoBasic
sUsername := "[email protected]"
sPassword := "password"
pmsg := ComObjCreate("CDO.Message")
pcfg := pmsg.Configuration
pfld := pcfg.Fields
pfld.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") := nSend
pfld.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") := 60
pfld.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") := sServer
pfld.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") := nPort
pfld.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") := bTLS
pfld.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") := nAuth
pfld.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") := sUsername
pfld.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") := sPassword
pfld.Update()
pmsg.From := sFrom
pmsg.To := sTo
pmsg.Subject := sSubject
pmsg.TextBody := sBody
pmsg.AddAttachment(sAttach)
pmsg.Send()
}
}
soundbeep
exitapp
The firewall settings for each computer allow outbound connections automatically. Can anyone see anything wrong with script, suggest a fix or offer an alternative method to send emails automatically? Thanks.---------------------------
SendEmail.ahk
---------------------------
Error: 0x80040213 -
Source: CDO.Message.1
Description: The transport failed to connect to the server.
HelpFile: (null)
HelpContext: 0
Specifically: Send
Line#
109: pfld.Item("http://schemas.microsoft.com/cdo/config ... ndpassword") := sPassword
110: pfld.Update()
112: pmsg.From := sFrom
113: pmsg.To := sTo
114: pmsg.Subject := sSubject
115: pmsg.TextBody := sBody
116: pmsg.AddAttachment(sAttach)
---> 117: pmsg.Send()
118: }
119: }
153: SoundBeep
155: ExitApp
156: Exit
157: Exit
157: Exit
Continue running the script?
---------------------------
Yes No
---------------------------