Generate/send email when a feature is added to a hosted service

18323
67
Jump to solution
02-24-2015 09:47 AM
ChandreyeeLahiri
New Contributor III

Is it possible to have an email sent (to a list of recipients) whenever a point is added to a hosted File GDB on a public web-app?

 

The idea is to originate a permit application process from a web-map/app: applicants can add a point for the location they need a permit for, enter their information and apply for a permit (of particular kind). An email alerts officials that a permit has been applied for. The rest of the approval process flow from there and the hosted data is used to collect applicant information (including location for permit) as well as flag the status of the application as it makes its way through various stages of the approval process.

 

Any ideas on how to have edits trigger emails?

67 Replies
AlexP_
by
Occasional Contributor III

I understand. Please see zip file attached. Thank you for your time and assistance. 

0 Kudos
EdwardHankins
New Contributor II

Can you turn the service back on,  i tried to test your script but it is failing because it is disabled.  

but just from what i can see,  you will need to change lines 35 and use your Created Date field instead of my ['Date_Notified'] field.  Also you need to remove the zone = feat... line and fix line 40 to be something like

if createDate > t: 

let me know when you turn the service back on and i will check some more. 

0 Kudos
AlexP_
by
Occasional Contributor III

Ok. I recent revised it what you mentioned above. It is enabled on to public and it is secured feature server URL. I also created a new feature point today. 

0 Kudos
AlexP_
by
Occasional Contributor III

I tried to run it but still having an issue with oidlist and subject error. Please advise.

Thank you, Alex

0 Kudos
EdwardHankins
New Contributor II

I took your script and rewrote some parts of it,  the finished copy is located here: https://ufile.io/9emzw 

It queries your REST service and returns all records,  from all the records it finds any record with a create date made in the last 10 days,  it then creates a list of those and formats them into an email (body, subject, etc...) 

The rest of the email part you will have to put in your email server and credentials to complete.  

From: xxxxxxxxxxx\n

To: xxxxxxxxxxxxxxxx\n

Subject: You Have 4 New Service Request(s) Added to the GIS Records since: 2019-03-31 18:46:55\n

\n1)  Feature with ID # 0145 created on 2019-04-05 14:26:42 was added to the GIS Records.  LOCATION: 1526 NW 89 CT\n\tSUMMARY: 201705896\r

\n2)  Feature with ID # 0145 created on 2019-04-05 20:20:23 was added to the GIS Records.  LOCATION: 5200-5292 NW 84th Ave, Miami, Florida, 33166\n\tSUMMARY: TEST\r

\n3)  Feature with ID # 0144 created on 2019-04-05 20:23:20 was added to the GIS Records.  LOCATION: 4800 NW 79th Ave, Miami, Florida, 33166\n\tSUMMARY: TEST\r

\n4)  Feature with ID # 0145 created on 2019-04-08 14:22:06 was added to the GIS Records.  LOCATION: 8401 NW 53 TER\n\tSUMMARY: TEST\n'

That is how the email will look (ignore the character tabs and escapes,  outlook will format them as HTML) 

0 Kudos
AlexP_
by
Occasional Contributor III

Thank you for your assistance. I revised and input email server/credentials. I tried to run it. Please see screenshot. I am using 2.7.13 python.. Am I doing anything incorrect?

0 Kudos
EdwardHankins
New Contributor II

what line is it saying your error is in?  i would also use pyscripter as your IDE, it gives much better information about errors.  

The script (lines 1-74) runs perfectly for me,  i did not not mess with the smtp part at the bottom (lines 75-82)

so i would imagine your syntax error is in lines 75 to 82.  I would look up the documentation on SMTP and then make yours look like that. 

0 Kudos
AlexP_
by
Occasional Contributor III

Please see screenshot with pyscripter. The line where the subject is # 64. I am looking up on smtp doc.

0 Kudos
EdwardHankins
New Contributor II

i think the syntax is with the line above that, the line that starts with TO

I think it is missing the closing "]"

it should be TO = ['yourname@email.com'] 

0 Kudos
AlexP_
by
Occasional Contributor III

You are correct. I revised it and it finally came thru to email. Thank you for your time and assistance on this matter.

0 Kudos