Citizen Problem Reporter - email notifications

2206
5
Jump to solution
10-08-2020 01:41 PM
Labels (1)
RDCOGIS
New Contributor III

Is it possible to send emails to multiple recipients?

https://solutions.arcgis.com/local-government/help/citizen-problem-reporter/get-started/email-notifi... 

I've used very similar email code in the past in my own environment and have been able to send multiples and it looks like the code is written to work with multiple recipients but it will only send to the first one in my list.

I've tried ; and , as delimiters and verified that both emails are valid

If anyone else can email to multiples 'out of the box' then I will search another avenue, maybe they are being blocked as spam....

Thanks

0 Kudos
1 Solution

Accepted Solutions
RDCOGIS
New Contributor III

the better solution is to not mess with the send_mail.py but instead reconfigure the build_email function in servicefunctions.py to build a proper list. I changed the variable from 'email' to 'recipients' but regardless, this builds a list when supplied ; separated addresses in config file.

this still allows to use both an manual address or one from attribute table.

recipients = []
rr = settings['recipient'].split(';')
for r in rr:
if r in row.fields:
recipients.append(row.attributes[r])
else:
recipients.append(r)

View solution in original post

5 Replies
RickeyFight
MVP Regular Contributor
RDCOGIS
New Contributor III

Thanks, I got it working by manipulating the 'recipients'. I couldn't get the right syntax to flow from the json config file to the python.

a few notes:

  • Putting a list in the config errors the script
  • Putting "name1@email.com;name2@email.com" translates to a list with only one object ["name1@email.com;name2@email.com"]
  • I added this to the Python send_mail to switch to a proper list: 
    • recipientsList = recipients[0].split(';')
    • creates: ["name1@email.com", "name2@email.com"]

The link above (Ricky's) shows these scripts nice and compact with no config file, the full solution (top link) has these files broken apart and maybe no-one tested multiple recipients set from inside the config file.

0 Kudos
RDCOGIS
New Contributor III

the better solution is to not mess with the send_mail.py but instead reconfigure the build_email function in servicefunctions.py to build a proper list. I changed the variable from 'email' to 'recipients' but regardless, this builds a list when supplied ; separated addresses in config file.

this still allows to use both an manual address or one from attribute table.

recipients = []
rr = settings['recipient'].split(';')
for r in rr:
if r in row.fields:
recipients.append(row.attributes[r])
else:
recipients.append(r)

JamesBurton1
Occasional Contributor

Any chance you could share the syntax of your build_email function after implementing this? 

0 Kudos
RDCOGIS
New Contributor III

Hi James, sure thing. 

Here is what I modified. The call from main to build_email will look like this. The build_email will return all three address (recipient) types:

for row in rows:
	address, address_cc, address_bcc, subject, body = build_email(row, lyr.properties.fields, message)

 

In build_email I retrieve the three address types from the config file and call a new _get_email_values function.

recipients    = _get_email_values(row, fields, settings['recipient'])
recipients_cc = _get_email_values(row, fields, settings['recipient_cc'])
recipients_bcc = _get_email_values(row, fields, settings['recipient_bcc'])

..
..
..

return recipients, recipients_cc, recipients_bcc, email_subject, email_body

I attached the _get_email_values as a txt. It is quite convoluted and can be simplified just to the top two lines if you wanted to (after .split(;)). The full function (aside from that it could be written better....) will either....

1. return the address directly as in the config if it detects an '@'

2. get the address from the data if it detects that you used a field name

3. get the address from the data's domain if it detects that you used a field name and the field is a Domain

Hope this makes sense, I found the _get_email_values a bit tough to read after leaving it for a few months.

 

Dave