Select to view content in your preferred language

Send E-mail Notifications with ArcGIS Notebooks - Online

2141
13
09-18-2023 09:24 AM
Labels (1)

Send E-mail Notifications with ArcGIS Notebooks - Online

Recently I was working with a customer that wanted to send an e-mail notification from ArcGIS Online Notebooks.  I’ve come to find that ArcGIS Online notebook containers have a blocking firewall that blocks the outbound SMTP connection.  So, we were unable to connect to an external SMTP server (i.e. Office365) to send an e-mail.  However, we were able to find a workaround using the Group object’s notify method.

The notify method can send an e-mail to any or all users in a Group.  In this example, the customer wanted to notify a user that their account would be disabled when they haven’t logged in within 90 days.

1.  First step is to create a Group in AGOL.  Since any user could potentially be notified, all named users have been added to this group, All Users.  No content needs to be shared to this Group, so I’ve set the Contributors to only the group owner and managers:

JakeSkinner_0-1695053656490.png

 

2.  Make note of the Group ID from the URL:

JakeSkinner_1-1695053656492.png

 

3.  Reference this group in your Notebook:

JakeSkinner_2-1695053656493.png

 

4.  Create a list of all named users

JakeSkinner_8-1695053880983.png

 

5.   Check which users have not logged in within 90 days.  Disable those accounts, and add that username to a list called userList

JakeSkinner_4-1695053656494.png

 

6.   If there were users that were disabled, the userList can be passed to the notify method with an e-mail subject and message of your choice:

JakeSkinner_5-1695053656495.png

 

Example e-mail message:

JakeSkinner_6-1695053656496.png

 

Attached is the Notification Example notebook/script.

Labels (1)
Attachments
Comments
DavidPike
MVP Frequent Contributor

This is really handy, thanks Jake.

How do you manage adding new users to the 'all users' group over time?

JakeSkinner
Esri Esteemed Contributor

@DavidPike when a new user is added to Portal, you can add them immediately to the 'all users' group during the account creation steps.  Another way would be to create a script that checks all named users in the Org and compare them to the named users in the 'all users' group.  If a user is missing, the script could add the user to the group.

SFM_TravisBott
Occasional Contributor III

@JakeSkinner Is there a way to format email notifications at all? The Python text delimiters don't seems to be honored at all and I need to send a more complex message. 

JakeSkinner
Esri Esteemed Contributor

@SFM_TravisBott I believe only basic HTML formatting is supported (i.e. bold, italics, etc).  I tested an e-mail trying to send a hyperlink, and it failed.

SFM_TravisBott
Occasional Contributor III

@JakeSkinner Thanks for the heads up. You say 'you believe...' Who knows the answer definitively?

tmichael_wpjwa
New Contributor III

@SFM_TravisBott I've been able to add various HTML formatting tags to my output email (bold, paragraph, style, break, link) and that approach has worked.

SFM_TravisBott
Occasional Contributor III

@tmichael_wpjwa was this after the recent update or before?

tmichael_wpjwa
New Contributor III

@SFM_TravisBott I just started tinkering with the group notify functionality within the last couple of months after finding this article, so possibly before the latest update but definitely after.  In one of my notebooks I'm pulling attributes from a feature layer and sending them via email like this:

email_message += "<b>" + f"{i.attributes['LOCDESC']}" + "</b>" + "<br>"
email_message += f"Earliest test date: {earliest_sample_date}" + "<br>"
email_message += f"Phone Number: {i.attributes['PhoneNumber']}" + "<br>"
email_message += f"Email: {i.attributes['EmailAddress']}" + "<br>"
email_message += "<br>"

email_message += "Click here to view the dashboard:" + "<br>"
email_message += "<a href=\"<dashboard url>\">Dashboard Link</a>"

 

James_Shreeve
New Contributor III

Hi @JakeSkinner, I know this post is a bit old now but I've only just come across it. I'm looking to do similar and think Notebooks is probably the best way to do it...i'm looking to try and send an email based on a date field in a feature service layer. Essentially, I want the email to act as a reminder as the date approaches e.g. the date on the feature service layer is 25/12/2024 so I would like to be able to email certain users on the 25/06/2024 to say there is 6 months until this date. 

Do you think this is possible? I've tried to utilise the code above but not really getting anywhere, I must say i'm not to much of a Notebook/Python user. 

Thanks!

JakeSkinner
Esri Esteemed Contributor

@James_Shreeve is the email address in another field within the feature service?

James_Shreeve
New Contributor III

@JakeSkinner it isn't, no. Potentially I could add it in if it made the process easier though...I wasn't sure if I could use usernames in a group as with the above to act as the email address?

JakeSkinner
Esri Esteemed Contributor

@James_Shreeve yes, this would work.  When using a group to notify users, as in this document, all users will be notified that are in the group.  Not sure if this is what you're looking for, or to simply notify an individual user based on the particular feature.

Here is a document that shows how to query a feature service based on a date field.

James_Shreeve
New Contributor III

@JakeSkinner the users i'd need to notify are based on internal job roles so wouldn't really change, or could be easily changed within the group if needed I guess. Ideally i'd want the process to check a range of features not one inparticular. 

I'll have a look through the document linked and try and amalgamate the two processes. Thanks!

Version history
Last update:
‎09-18-2023 09:24 AM
Updated by:
Contributors