AnsweredAssumed Answered

ArcGIS Notebooks Administration: Deploy automatic notifications

Question asked by on Apr 17, 2020

Hi, I had watched a very useful tutorial video by Shannon Kalisky and thought i would look into notebooks.


I am trying to use the sample Administration: Deploy automatic notifications Notebook to send an email but i seem to be running into issues and getting an error setting up SMTP server. have tried this using my work email and also my personal hotmail email.I have used the sample notebook as is until the add secret part where i add my email password to the csv.


My code for the smpt server part is as follows:


def send_email_smtp(recipients, message,
subject="Message from your Notebook"):
"""Sends the `message` string to all of the emails in the
`recipients` list using the configured SMTP email server.
# Set up server and credential variables
smtp_server_url = ""
smtp_server_port = 587
sender = ""
username = ""
password = secrets["smtp_email_password"]

# Instantiate our server, configure the necessary security
server = smtplib.SMTP(smtp_server_url, smtp_server_port)
server.starttls() # Needed if TLS is required w/ SMTP server
server.login(username, password)
except Exception as e:
log.warning("Error setting up SMTP server, couldn't send " +
f"message to {recipients}")
raise e

# For each recipient, construct the message and attempt to send
did_succeed = True
for recipient in recipients:
message_body = '\r\n'.join(['To: {}'.format(recipient),
'From: {}'.format(sender),
'Subject: {}'.format(subject),
message_body = message_body.encode("utf-8")
server.sendmail(sender, [recipient], message_body)
print(f"SMTP server returned success for sending email "\
f"to {recipient}")
except Exception as e:
log.warning(f"Failed sending message to {recipient}")
did_succeed = False

# Cleanup and return
return did_succeed

I then try and send as follows:

send_email_smtp(recipients = [''],
message = "Hello World!")

Am i doing something silly? Any help would be greatly appreciated. I am looking to figure this part out and then move on to using the Manage inactive users notebook.