I'd like to make a model with a last step, a python script, that will send an email, containing messages and status of the model. The email sending part is okay, nut the hard part for me is to query the status and the message. I found the "result" and the "GetMessages" things but could not succeeded.

I'd like to make it work on a really simple model than use it when its needed. The dummy model looks like this:


And the script:

import arcpy
result = arcpy.topmodel_tulboksz()
print result.getMessages()
  • 3
    What, specifically, happened when the script did not succeed? Are you getting error messages? Can you post some of your code and an outline of your model, and how the two are connected? Mar 21, 2016 at 14:20
  • result.status indicates if the last step succeeded
    – klewis
    Mar 21, 2016 at 14:32

1 Answer 1


The easiest way to do this might be to turn your email script into a wrapper script round around your model (run a tool inside a tool). This script would call your script, catch any errors and then send an email with the result.

If your email script is in the form:

import arcpy
import os.path

    path = arcpy.GetParameterAsText(0)
    params = arcpy.GetParameter(1)

    tbx_path, selected_tool = os.path.split(path) # Split so you have the toolbox and tool name

    tbx = arcpy.ImportToolbox(tbx_path) # import the toolbox
    tool = getattr(tbx, selected_tool) # get the tool by name from the toolbox
    result = tool(*params) # run the tool with all the required parameters
    messages = arcpy.GetMessages()
    status = result.status # Will be 4 on successful completion - see http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-classes/result.htm
except Exception as e:
    messages = arcpy.GetMessages(2) # get only the error messages (alternately just use the exception object)
    status = 5 # For Failed

# Send your email with your messages here

If you then add the script to a toolbox with two parameters:

  • The first should have a Data Type of Tool, which will be the model you're interested in running
  • The second should have a type of Any value, which will contain any arguments you might need to pass to your model, in order (including output parameters). This should be set to accept multiple values, and be an optional parameter.

Then run the model by using your email script as the wrapper, and you will get an email back with the status of the tool.

  • Henry! I tried it but something not working. I aint got no email when the script/model fails. Here is my whole script: pastebin.com/ZXdDNymC The script/tool/model should be able to send the email if the process fails or not. Now It send the email only when it not fails. Here is an additional image <img src="i.imgur.com/uuPogqs.png"> please help me, what did I wrong?
    – STO
    Mar 30, 2016 at 15:37
  • @STO I've updated the answer so it's a bit more explicit - if the tool fails before you get the result object in the try then status wasn't being set. That's what it looks like is causing the message to fail generating if the script fails. Also, to make it a bit more usable I'd set the second parameter to accept multiple inputs so it can be ussed with any tool. If you've still got issues it's probably best to take this to a chat room - feel free to set one up and ping me.
    – om_henners
    Mar 30, 2016 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.