Send Email within an ArcGIS Script

EmailHere are a couple of code snippets that we use to send an email after an ArcGIS Script (Model Builder) runs successfully. We like to use this code when running automated (scheduled) ArcGIS scripts when no one is around during off-hours. When the script is executed, this code will send an email to an individual email or multiple email addresses delivering a message. This has been tested on WinXP, W2k, & Windows 2003 Server. Let me know if it works under other platforms or if you have any problems or enhancements.

Here is how it works.

  1. Build a model using “Model Builder” inside ArcToolbox.
  2. Once you have the Model built and functioning properly, export the model to vbScript from Model Builder.
  3. Edit the vbScript with notepad and “add”either one of the following pieces of code below.
  4. I have included code for both POP3 and IMAP/Exchange mail servers. Fill in your email information everywhere you see Bold & Italic Text in the example code below.

For POP3 Email Servers

Const cdoSendUsingPickup = 1 ‘Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 ‘Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 ‘Do not authenticate
Const cdoBasic = 1 ‘basic (clear-text) authentication
Const cdoNTLM = 2 ‘NTLM

Set objMessage = CreateObject(”CDO.Message”)
objMessage.Subject = “Enter Email Subject here
objMessage.From = “”"ArcGIS”" <Enter FROM Email Address Here>”
objMessage.To = “Enter TO Email Address Here
objMessage.TextBody = “Enter Email Body Here..” & vbCRLF & “Thanks, ArcGIS”

‘==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2

‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpserver“) = “Enter SMTP Server Here

‘Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpauthenticate“) = cdoBasic

‘Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/sendusername“) = “Enter Email Username Here

‘Your password on the SMTP server
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/sendpassword“) = “Enter Email User Password Here

‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25

‘Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpusessl“) = False

‘Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout“) = 60

objMessage.Configuration.Fields.Update

‘==End remote SMTP server configuration section==

objMessage.Send

For IMAP Exchange Servers

Set objMessage = CreateObject(”CDO.Message”)
objMessage.Subject = “Enter Email Subject Here
objMessage.From = “Enter FROM Email Here
objMessage.To = “Enter TO Email Here
objMessage.TextBody = “Enter Email Body Here.”

‘==This section provides the configuration information for the remote SMTP server.
‘==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/sendusing“) = 2

‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpserver“) = “Enter IP of Exchange Server Here

‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(”http://schemas.microsoft.com/cdo/configuration/smtpserverport“) = 25

objMessage.Configuration.Fields.Update

‘==End remote SMTP server configuration section==

objMessage.Send

Leave a Reply