AnsweredAssumed Answered

ArcGIS Notebooks Administration: Deploy automatic notifications

Question asked by ciaran.higgins@niwater.com 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.
"""
try:
# Set up server and credential variables
smtp_server_url = "smtp.live.com"
smtp_server_port = 587
sender = "myemail@hotmail.co.uk"
username = "myemail@hotmail.co.uk"
password = secrets["smtp_email_password"]

# Instantiate our server, configure the necessary security
server = smtplib.SMTP(smtp_server_url, smtp_server_port)
server.ehlo()
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:
try:
message_body = '\r\n'.join(['To: {}'.format(recipient),
'From: {}'.format(sender),
'Subject: {}'.format(subject),
'',
'{}'.format(message)])
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}")
log.warning(e)
did_succeed = False

# Cleanup and return
server.quit()
return did_succeed

I then try and send as follows:

send_email_smtp(recipients = ['adifferentemail@gmail.com'],
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.

 

Thanks 

Ciaran

Outcomes