This script has been moved to mature support.

Send email notifications

Many workflows require that an email be sent when a feature or record is created and updated. The email notification script can be used to generate emails with a message of your choosing and send those emails to users at regularly scheduled intervals of your choosing.

Configuring and executing this script requires the following components:

Once these components are installed, make sure that your Python IDE is set to work against your Python 3 installation that contains the ArcGIS API for Python library (for example, <default directory>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-python3\python.exe), and then skip ahead to the steps for configuring the script.

To set up the email notification script, complete the following steps:

  1. Your data will need a text field to track the status of the email notifications you are configuring. If your data does not have a field with a series of values that can be used to determine which emails have been sent and which are pending, add one that can be used for this purpose.
  2. Open and locate the line that contains orgURL =. Between the quotation marks, provide the URL to your ArcGIS organization, and on the two subsequent lines, provide the user name and password to an account in this organization that can edit the services you will be using to trigger messages.
  3. Following the login information is a section for configuring the script to work with your email server. Provide the URL of your SMTP server, the user name and password of an email account on that server, the address from which the emails should be sent, and the reply address.
  4. Locate the line that contains email_services = [. Use this section to configure which services should trigger email messages and the messages that should be sent for each service.
  5. Provide the URL to the REST endpoint of the first service, including the feature layer index number, for the 'service url' parameter.
  6. Following the service URL is a list of messages that can be sent for this service. For each message, provide the following values:
    • 'query' : Provide an SQL WHERE clause used to identify the features that require this message. For example, use "STATUS = 'Submitted' AND PRIORITY = 1" to only send this message for reports that have both the value 'Submitted' in the text field STATUS and the value 1 in the numeric field PRIORITY. Pay close attention to the use of double quotation marks to surround the entire clause, single quotation marks around the text field values, and no quotation marks around values from numeric fields. All field names and values are case-sensitive.
    • 'email address' : Email address, or name of the field containing the email address, where the notification should be sent.
    • 'email body template' : The email notification scripts are delivered with a series of HTML email templates. Edit the provided templates to your own formatting and content, and create new templates following this format as necessary. These templates can contain variable strings, configured in the 'body substitutions' parameter, which the script will exchange for static values, or attribute values specific to the feature triggering the email. For this parameter, provide the relative path to one of these templates.
    • 'email subject' : Subject of the email sent to the user.
    • 'body substitutions' : Pairs of strings and values or strings and field names used to customize the text in the body of the email. It is strongly recommended to use special characters in these strings to avoid accidentally substituting the wrong content. For example, include the string Hello, {name} in the email template and set the body substitution value to '{name}': 'NAME' to replace {name} with the value in the NAME field of the report. If the service does not contain a field with the name NAME, the email will exchange the characters for the literal string provided. For example, if the body template contained Thank you for the {report type} report and the message was configured with the substitution {report type}: 'abandoned vehicle', the outgoing email would contain the message 'Thank you for the abandoned vehicle report'.
    • 'status field' : Provide the name of a text field that will be used to track which features have already triggered this message. The query for this message should reference this field and the value that indicates that this message is required. Once the email has been sent, the value will be updated to the value provided in the completed value parameter for the message.
    • 'completed value' : Value for the status field that indicates that this message has been sent.
  7. Additional messages can be configured for the service by adding blocks of these parameters, surrounded by curly braces {}. The parameters for each message must be separated with a comma. All of the messages for a service must be surrounded by a single set of square brackets [].
  8. Additional services can be configured for the script by adding sets of service URL and message parameters, surrounded by curly braces {}. The parameters for each service must be separated with a comma. All of the services and their parameters must be surrounded by a single set of square brackets [].
        email_services = [
        {'service url': '',
            'messages': [
                {'query': "STATUS='Send 1st email'",
                'email address': 'EMAIL',
                'email body template': './email_template_1.html',
                'email subject': 'Thanks for the report',
                'body substitutions': {'{name}': 'NAME',
                                        '{report type}': 'REPORTTYPE'},
                'status field': 'STATUS',
                'completed value': 'Send 2nd email'},
                {'query': "STATUS='Send 2nd email'",
                'email address': '',
                'email body template': './email_template_2.html',
                'email subject': 'Report received',
                'body substitutions': {'{manager name}': 'Jane Smith'},
                'status field': 'STATUS',
                'completed value': 'Emails sent - waiting for manager approval'}
        {'service url': '',
            'messages': [
                {'query': "STATUS='Send 1st email'",
                'email address': 'EMAIL',
                'email body template': './email_template_1.html',
                'email subject': 'Thanks for the report',
                'body substitutions': {'{name}': 'NAME',
                '{report type}': 'REPORTTYPE'},
                'status field': 'STATUS',
                'completed value': 'Send 2nd email'}
  9. Before continuing further, it is strongly suggested that the configured script be run again with some sample features you create in your dataset to test the organization connection, email server connection, sequencing of messages, and message content.

Set up Task Scheduler

Use Windows Task Scheduler to schedule the script to regularly scan the configured services and send email messages as appropriate.

  1. Open the Task Scheduler on the desktop computer that is hosting the scripts.
  2. Click Action > Create Task and name your task.
  3. Click the Actions tab and click New.
  4. Set Action to Start a Program.
  5. Browse to the location of your Python 3 installation (for example, <default directory>\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-python3\python.exe).
  6. In the Add arguments text box, copy the name of the script (
  7. In the Start in text box, type the path to the folder containing the scripts and email templates and click OK.
  8. Click the Trigger tab, click New, and set a schedule for your task.
  9. Click OK.