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
try:
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.