Trigger an apps script function on sending Email

419 views
Skip to first unread message

Aayesha Shrestha

unread,
Jun 10, 2019, 2:52:08 AM6/10/19
to Google Apps Script Community
How can we trigger an apps script function to get sender, recipient, subject and body of the mail, when an email is sent from Gmail?

Davis Jones

unread,
Jun 10, 2019, 11:50:06 AM6/10/19
to Google Apps Script Community
I'm not an advanced developer, so take this worth a grain of salt, but I think you'd have to have the sender deploy the email from within your program (which is totally possible) in order for you to cause other triggers on the send of the email.

Aayesha Shrestha

unread,
Jun 11, 2019, 2:30:46 AM6/11/19
to Google Apps Script Community
what do you mean by having the sender deploy the email from within the program?

Alan Wells

unread,
Jun 11, 2019, 9:06:10 AM6/11/19
to Google Apps Script Community
There would need to be an "On Send Email" event.  The Apps Script documentation for event objects doesn't show any Gmail event handlers.

I took a quick look at the Gmail add-on docs and didn't see anything that would detect an email being sent.

What is the context of your situation?  Do you want to know every time that an employee sends an email?  Do you want an email sent, when someone edits a spreadsheet cell?

Aayesha Shrestha

unread,
Jun 12, 2019, 1:14:52 AM6/12/19
to Google Apps Script Community
There is no spreadsheet and I don't want to save every email , but to save the message and body (in a third party application) of the mails for which the sender has checked a checkbox in composeUI. I could not find any event for "On Email Send". 

Aayesha Shrestha

unread,
Jun 12, 2019, 1:15:01 AM6/12/19
to Google Apps Script Community
There is no spreadsheet and I don't want to save every email , but to save the message and body (in a third party application) of the mails for which the sender has checked a checkbox in composeUI. I could not find any event for "On Email Send". 

On Tuesday, June 11, 2019 at 6:51:10 PM UTC+5:45, aj.addons wrote:

Alan Wells

unread,
Jun 12, 2019, 8:22:22 AM6/12/19
to Google Apps Script Community
Your app would need to have the user send an email by clicking something in the app rather than in Gmail.  That's the only way that you could know for sure whether the email was sent.  Other than that, you'd need your app to run on a time trigger and go through emails and determine which ones were processed already and which ones weren't.
Reply all
Reply to author
Forward
0 new messages