Send email from Quick Report app when user clicks submit button?

1990
6
Jump to solution
03-24-2017 01:43 PM
KE
by
Occasional Contributor

Is it possible to send an email from the Quick Report mobile app?

When a user submits a report through the app, I need to alert my customer that a report has been added. This is for public safety, so I do not want to "check" for a added record at intermittent periods, they need to be alerted immediately when a record is added.

The feature class lives in our enterprise SDE database and the feature service is published on our ArcGIS Server.

I had previously set up a SQL Server database trigger, but I cannot get it to work properly. Even with an insert trigger, it still sends an email when a record is deleted.

I am using AppStudio for ArcGIS (Desktop Edition) 1.4.18 and the quick report template.

App is currently in testing mode using AppStudio Player.

App needs to work in Android and iPhone.

1 Solution

Accepted Solutions
SathyaPrasad
Esri Contributor

Can be easily done by adding one additional call while submitting the report.

Problem is that to send an email you need to make SMTP call to an email server usually done via web service or proxy service or Amazon SES with API gateway or Google cloud functions or some other provider like Zapier to help you send emails. QML/AppStudio does not have native support to make SMTP calls directly (not recommended either). Once you have this established you can call this web endpoint while submitting the report with any information you want.

For example: Here is a link showing how PHP developers would do it: PHP: mail - Manual 

Once you have an url that can help you send email to your clients you can call this from the Quick Report app using NetworkRequest object.

File: FeatureServiceManager.qml (under controls folder)

1. Create a NetworkRequest object to call the webservice url to send an email

NetworkRequest
{
  id: emailHandler
  url: "<your http link to webservice>"
  method: "POST"
  onReadyStateChanged: {
     if (readyState === NetworkRequest.DONE ){
         if (errorCode!=0) {
            console.log("Network error!");
            //do something, may be retry later
         } else {
            //success.  
         }
      }
   }
  function sendEmail(recipients, heading, body) {
var obj = {};
obj.emailRecipients = recipients.toString();
obj.emailHeading = heading.toString();
obj.emailBody = body.toString();
send(obj)
  } 
}

2. Call this new emailHandler when submitting report inside of the "applyEdits" function at the end.


Hope this helps.

View solution in original post

6 Replies
SathyaPrasad
Esri Contributor

Can be easily done by adding one additional call while submitting the report.

Problem is that to send an email you need to make SMTP call to an email server usually done via web service or proxy service or Amazon SES with API gateway or Google cloud functions or some other provider like Zapier to help you send emails. QML/AppStudio does not have native support to make SMTP calls directly (not recommended either). Once you have this established you can call this web endpoint while submitting the report with any information you want.

For example: Here is a link showing how PHP developers would do it: PHP: mail - Manual 

Once you have an url that can help you send email to your clients you can call this from the Quick Report app using NetworkRequest object.

File: FeatureServiceManager.qml (under controls folder)

1. Create a NetworkRequest object to call the webservice url to send an email

NetworkRequest
{
  id: emailHandler
  url: "<your http link to webservice>"
  method: "POST"
  onReadyStateChanged: {
     if (readyState === NetworkRequest.DONE ){
         if (errorCode!=0) {
            console.log("Network error!");
            //do something, may be retry later
         } else {
            //success.  
         }
      }
   }
  function sendEmail(recipients, heading, body) {
var obj = {};
obj.emailRecipients = recipients.toString();
obj.emailHeading = heading.toString();
obj.emailBody = body.toString();
send(obj)
  } 
}

2. Call this new emailHandler when submitting report inside of the "applyEdits" function at the end.


Hope this helps.

View solution in original post

deleted-user-lwkurIII0T1f
New Contributor II

I have the same question as Christina Chelf. What would the email URL look like? I haven't had any luck making that work. Also, how do you call the emailHandler? Does this function simply enable a mailto pop-up or is there a way to have the email sent automatically, without having to be sent by the user?

0 Kudos
JaysonWard
New Contributor III

Hi Jennifer:

If you or another person is following the PHP example in Sathya's response above, the url would really just be a link to a .php page on a web server (ex: http://www.yourwebserver.com/handlemail.php).  The handlemail.php would read the email's body passed via the POST request and use PHP to send an email.

For zapier, or some other 3rd party service, the url should be denoted somewhere your account settings. Most likely that url will be to a REST service that accepts the POST request sent by NetworkRequest in the example above. You will most likely have to pass additional parameters such as a unique client id associated with your account along with the email body. The 3rd party service should tell you what to pass to the service. 

As for calling the sendEmail function, inside applyEdits function you would call emailHandler.sendEmail(recipients, heading, body); for example:

emailHandler.sendEmail("therecpients_email@you.com", "A cool heading", "This is the email body");

deleted-user-lwkurIII0T1f
New Contributor II

I actually figured this out right after I posted that question. I might try to post my solution later today. Thanks for the reply!

0 Kudos
ChristinaChelf2
New Contributor

This is really helpful! I have a few questions:

I set up a Zapier account and set up an email to email zap. So when someone emails

example.osu0cx@zapiermail.com it is sent to my inbox. Is this all i need for the "url" or do I need some somethign else?

I am new to using QML, how exactly do I call the emailHandler in the applyEdits function?

Thanks!

0 Kudos
GiatriLalla
New Contributor III

Hi,

I am also new to QML and want to find out how to call the emailHandler in the applyEdits function.

Thank you in advance.

0 Kudos