Select to view content in your preferred language

Future Date Email or SMS Notification Trigger

05-18-2021 04:49 AM
New Contributor

Please, is it possible to get a future email or SMS notification for a date question type (e.g. ${tenancy_expiry_date}) when the said date is due? I am working on a project work which aims to improve rent tax mobilization by the Ghana Revenue Authority (GRA). I want the Authority to be notified when a rent tenancy agreement expires. For instance, a 3-year rent agreement entered into force on March 5, 2021 will expire on March 5, 2024. On March 5, 2024, the application which is designed in Survey123 Connect and published to AGOL should trigger an email or SMS notification to GRA informing it of the tenancy agreement expiration. The Debts and Compliance Unit of the Authority can then follow up on a possibly renewed tenancy agreement to administer rent tax. I hope to find a solution to this challenge. Thanks in advance! 

0 Kudos
2 Replies
MVP Esteemed Contributor

Fancy was is using webhooks if you have access.

I think maybe Microsoft is an option now.

Or old school.  When I had to do this I wrote a Python script that runs every night using task scheduler.

This is Python 2.7 code but I would use Python 3 with ArcPro if possible (this will require some code change).  That way hitting a hosted feature service is way easier - just have Pro logged in and it uses its credentials.  

Create a layer file that has a query in it like LeaseExpire + 5 > today or something like that.  Then use that layer file in your script.

Name:       How to Send Email with

Author:     Doug Browning

Created:    12/7/2015
Updated:    05/19/2017

Purpose:    Shows how to send a email out with attachement

Changed:    Changed the smtp server due to move to outlook.
            Changed to work with GMail now

HTML and Attachemnt are turned off in this sample

import arcpy
import smtplib
import mimetypes
from email.mime.multipart import MIMEMultipart
from email import encoders
from email.message import Message
from import MIMEAudio
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.text import MIMEText

# May work
emailSMTP = ""
# Will work
#emailSMTP = ""
smtpusername = ""
smtppassword = "pass"

# Set To and From
emailfrom = ""
# Weird but the msg["To"] must be a string but the call to the smtp server must be a list see line 71.  not easy to figrue out
# List can be a single text also but easier to just always be a list so that split code works
# This is who it will send to.  Always make this a list so that the split and join below work
emailRecList = ["",""]      # or  emailRecList = [""]
# this is a text list it needs for the to
emailto = ','.join(emailRecList)

# give a path to a file or set a flag by setting = no
#fileToSend = r"c:\temp\temp.pdf"
fileToSend = "no"

msg = MIMEMultipart()
msg["From"] = emailfrom
msg["To"] = emailto
# Can set any Subject here
msg["Subject"] = "Form Attached"
# No Idea where this goes
msg.preamble = "Where is this"

# For text - plain or HTML
# Plain Sample
text = "Hi!\nHow are you?\nHere is the text you wanted."

# HTML sample
html = """\
       How are you?<br>
       Here is the <a href="">link</a> you wanted.

part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Uncomment out to send HTML

# For attachement
if fileToSend != "no":
    ctype, encoding = mimetypes.guess_type(fileToSend)
    if ctype is None or encoding is not None:
        ctype = "application/octet-stream"
    maintype, subtype = ctype.split("/", 1)
    fp = open(fileToSend, "rb")
    attachment = MIMEBase(maintype, subtype)
    attachment.add_header("Content-Disposition", "attachment", filename=fileToSend)

# Send section
#server = smtplib.SMTP(emailSMTP)
# for gmail
server = smtplib.SMTP_SSL(emailSMTP,465)
# for gmail
server.login(smtpusername,smtppassword)   # password not needed for here
# Weird but the msg["To"] must be a string but the call to the smtp server must be a list
server.sendmail(emailfrom, emailRecList, msg.as_string())

Hope that helps

Occasional Contributor III

I need to do this exact workflow. Is there any way to use Survey123 and Make to do this? 

0 Kudos