Select to view content in your preferred language

Issues getting Citizen Reporting Tool to send emails

367
3
08-27-2024 08:32 AM
TimHolsti
Emerging Contributor

Good morning,

I've been working on getting the automated email script to work, and have yet been able to get it to work.

I've attempted using SMTP for google and office365, all the ports I could find (25, 586, 587).

I've created a new field called email_status, and have the tool setup to update this field to sent, as well as the SQL query to only send records that have null or empty in the email_status field.

I reached out to another ESRI user that is having success, and looked over their files and I'm not seeing anything glaring.

I attempted to use make.com as well as powerautomate, however they are not detecting a change in my feature layer that contains where the requests are stored.

If anyone could provide any assistance, I would greatly appreciate it.

Thank you,

Tim

0 Kudos
3 Replies
Kara_Shindle
Frequent Contributor

when you use Make, are you using the "Field Maps Watch Service" module?

Can you post your email script?

0 Kudos
TimHolsti
Emerging Contributor

Kara,

Attached is the json . Additionally, this email address does not use MFA.

I am using the watch features module in Make.

Thanks

Tim

0 Kudos
Kara_Shindle
Frequent Contributor

So What are your Make settings?  I would think you have to get that working before the email will work?  Can you upload a screenshot of your scenario?  I found that mine didn't work until I added an Iterator because it changed the messages incoming from the Field Maps widget into packages that other modules could receive.

Kara_Shindle_0-1724933737518.png

Could you also paste your webhook settings?  Have you had Make successful receive messages on that particular webhook before?

Kara_Shindle_1-1724933835058.png

 

You could also use the Make module to set up the emails if the JSON is giving you grief.

 

Here is my Python script for using Google, don't know if that helps at all.

#!/usr/bin/env python3

"""
Python Script that will be used to notify staff of new additions
to the Citizen Problems feature in ArcGIS Online using the ArcGIS API for Python.

Notification is sent to the appropriate person when a new feature is found and the
feature is updated to Received

Python Path: Pyton 3.6.4 / C:\ProgramData\Anaconda3
"""
from arcgis.features import FeatureLayer
#import arcpy
import smtplib
import datetime


def sendTextNotification(requestType, contact, submittedOn, details):
	fromaddr = "email@org.gov"
	toaddr = "5555555555txt.att.net"
	sep = "\n"
	msg = (
		f"From: {fromaddr}{sep}"
		f"To: {toaddr}{sep}"
		f"Subject: New complaint - {requestType}"
		f"{sep}"
		f"A new complaint has been made: {sep}"
		f"Type of Problem: {requestType}{sep}"
		f"Name: {contact}{sep}"
		f"Date Submitted: {datetime.datetime.fromtimestamp(int(submittedOn)//1000)}{sep}"
		f"Details: {details}{sep}"
	)
	server = smtplib.SMTP('smtp.google.pathwayforourorg', port=25)
#	server.set_debuglevel(1)
	server.sendmail(fromaddr, toaddr, msg)

	server.quit()

def sendEmailNotification(requestType, contact, submittedOn, details):
	fromaddr = "email@org.gov"
	toaddr = "person@org.gov"
	sep = "\n"
	msg = (
		f"From: {fromaddr}{sep}"
		f"To: {toaddr}{sep}"
		f"Subject: New complaint - {requestType}"
		f"{sep}"
		f"A new complaint has been made: {sep}"
		f"Type of Problem: {requestType}{sep}"
		f"Name: {contact}{sep}"
		f"Date Submitted: {datetime.datetime.fromtimestamp(int(submittedOn)//1000)}{sep}"
		f"Details: {details}{sep}"
	)
	server = smtplib.SMTP('smtp.google.pathwayforourorg', port=25)
	server.sendmail(fromaddr, toaddr, msg)

	server.quit()

def main():
	layer =    FeatureLayer('https://myfeaturelayerservice/0')
	#Create query string
	queryString = "STATUS = 'Submitted'"

	#Query layer and send mail
	query_result1 = layer.query(where=queryString)
	if len(query_result1) > 0:
#		print(len(query_result1))
		featureUpdates = []
		for feature in query_result1.features:
			sendTextNotification(feature.attributes["REQTYPE"], feature.attributes["CONTACT"], feature.attributes["SUBMITDT"], feature.attributes["DETAILS"])
			sendEmailNotification(feature.attributes["REQTYPE"], feature.attributes["NAME"], feature.attributes["SUBMITDT"], feature.attributes["DETAILS"])
			sendEmailNotification2(feature.attributes["REQTYPE"], feature.attributes["NAME"], feature.attributes["SUBMITDT"], feature.attributes["DETAILS"])
			feature.attributes["STATUS"] = 'Assigned'
			feature.attributes["ASSIGNEDTO"] = 'User'
			featureUpdates.append(feature)

		layer.edit_features(updates=featureUpdates)



if __name__ == "__main__":
	main()

 

0 Kudos