This example will send emails from your Gmail account but it can be configured for other SMTP Servers. I use Gmail in this example because it's my preferred email service. See remarks in the script.
Known Issues:
Leaving VBSEmailAttachment empty will result in a noname 0K (Zero K) attachment in the email.
Tested in Windows Windows 7 Ultimate
Written with Macro Scheduler 12.1.4
Code: Select all
VBSTART
Function SendGmail(VBSEmailSubject,VBSEmailFrom,VBSEmailTo,VBSEmailBody,VBSEmailAttachment,VBSEmailServer,GmailUserName,GmailPassword,VBSServerPort,VBSEmailSSL,VBSEmailTimeout)
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoAnonymous = 1
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = VBSEmailSubject
objMessage.From = VBSEmailFrom
objMessage.To = VBSEmailTo
objMessage.TextBody = VBSEmailBody
objMessage.AddAttachment VBSEmailAttachment
'This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = VBSEmailServer
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = GmailUserName
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = GmailPassword
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = VBSServerPort
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = VBSEmailSSL
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = VBSEmailTimeout
objMessage.Configuration.Fields.Update
objMessage.Send
End Function
VBEND
'Email from
Let>VBSEmailFrom=Your Name <[email protected]>
'Email address to send email to
Let>[email protected]
'Email Subject
Let>VBSEmailSubject=VBscript Email Example by Rain
'Email Body Text
Let>VBSEmailBody=This email was sent with CDO
'Your Gmail UserID
Let>[email protected]
'Your Gmail Password
Let>GmailPassword=XXXXX
'Name of Gmail Remote SMTP Server
Let>VBSEmailServer=smtp.gmail.com
'Gmail Server port (typically 465)
Let>VBSServerPort=465
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the gmail server)
Let>VBSEmailTimeout=60
'Use SSL for the connection (Must Be True)
Let>VBSEmailSSL=True
//E.g. C:\Log.txt
//Leave Empty for no attachment
//Email will have an empty attachment
Let>VBSEmailAttachment=C:\Log.txt
VBEval>SendGmail("%VBSEmailSubject%","%VBSEmailFrom%","%VBSEmailTo%","%VBSEmailBody%","%VBSEmailAttachment%","%VBSEmailServer%","%GmailUserName%","%GmailPassword%",%VBSServerPort%,%VBSEmailSSL%,%VBSEmailTimeout%),res