email success/fail message when geoprocessing is finished?

08-23-2012 12:15 PM
New Contributor
Is it possible to email the success/fail messages when geoprocessing is finished? Perhaps with a Python script? This would drastically improve my efficiency on large datasets-- then I wouldn't have to babysit the computer for hours (since I can't know in advance whether it will be interrupted by a fail message due to memory issues).
0 Kudos
3 Replies
New Contributor III
The short answer is yes.

With Python you should be able to encapsulate your geoprocessing tasks in a Try Catch block and report back any error messages of the failed geoprocessing tasks.  After returning the error messages you would call your e-mail function.  Your e-mail function could then send the messages in one of two ways; either be writing them to a text file and then attaching the text file to the e-mail or the error messages could be passed directly into the body of the e-mail as part of the script.  If there are no errors you would not trip the Try Catch so then at the end of the geoprocessing tasks but inside the Try Catch you would want to call your e-mail function that could also be used to send an e-mail message by passing it a successful message.

There are plenty of examples of how to send e-mail with python on the internet with a bing or google search.

In my office we have some scripts that run as an automated process over the weekend while nobody is around.  It occasionally fails so we have some code to detect a failure and automatically restart the process.  The process generally takes 12 hours so it also will only restart if it has failed less than three times already or has enough time to complete before the Monday workday starts.

I know I didn't get into much specifics but at least this should give you some hope and a general idea of how to accomplish this.

0 Kudos
Regular Contributor III

Haven't tried it myself but it seems as there is such a script here:

and something similar in here:
0 Kudos
Esri Contributor

Here is the code that you can send the mail. We are considering adding the Email tool as part of the system tool for 10.1 SP2. You do need ot know the SMTP email server that is either located within your company, or any major email carrier such as Goole or Yahoo mail Server.

def emailResult(emailTo):

    global EC
    import smtplib

    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText

    FROM = ''
    TO = emailTo
    msg = MIMEMultipart('alternative')
    msg['From'] = "''"
    msg['To'] = emailTo 
    msg['Subject'] = "gp publishing results"

    plainMsg = MIMEText(EC, 'plain')
    htmlMSG = MIMEText(EC, 'html')
    # Send the mail
    server = smtplib.SMTP("")
    server.sendmail(FROM, TO, msg.as_string())
0 Kudos