0

I am developing a sheets addon, which lets the user send an email. The send function is called when the user clicks a button in a dialog which issues a google.script.run execution which then calls a server function that calls MailApp.sendMail.

The app has the permission script.send_mail as described here and works fine for me (a 'project editor') whenever I run it from the dialog.

Now, I am trying to get the addon approved for the marketplace but the email does not send when triggered by the marketplace reviewer user - they definitely did try as I have a lot of logging. No error is thrown by the sendMail function. The email address they are using is valid and the same email will send when I trigger it from the editor.

I think it may be a permission problem - but I don't know what.

I would like to recreate this by having a non-owner install the addon, but AFAICT it is not possible to install the addon for a non-owner (without it being in the marketplace ofc).

An alternative API might be GmailApp.sendEmail(), but the addon doesn't need access to the users own emails so that would be unnecessary privilege.

If anyone has any suggestions they would be much appreciated.

henryw374
  • 377
  • 4
  • 14
  • What type of trigger are you using? [Simple triggers](https://developers.google.com/apps-script/guides/triggers) cannot access services that require authorization. For example, a simple trigger cannot send an email because the Gmail service requires authorization. – Lorena Gomez Mar 03 '23 at 19:13
  • There is no trigger being used here. Sorry, bad wording on my part... Reworded now – henryw374 Mar 04 '23 at 19:11
  • Have you tried with another account besides the 'project editor' one and by any chance do you know if the email is in the user's 'sent' folder? – Lorena Gomez Mar 07 '23 at 14:07
  • I don't think it is possible to try with another account ( as per question I link to ) but please let me know if it is possible. This API does not put email in users sent items – henryw374 Mar 07 '23 at 21:28
  • It might have something to do with email domain. found this old issue: https://issuetracker.google.com/issues/36755057 – henryw374 Mar 09 '23 at 07:43
  • If you're using MailApp.sendEmail() then the email should appear in the 'Sent' folder. If this works when you're running it, can you confirm if it does appear in your sent items? – Lorena Gomez Mar 09 '23 at 14:10
  • ah sorry Lorena you're right. it does put the item in sent items. I will try to find out if it appears there for the marketplace user or not. thanks – henryw374 Mar 10 '23 at 11:14

2 Answers2

1

You can create a test deployment to test the add-on with additional accounts. Those accounts do not need to be the owner of the script project but they need edit access.

Another way to test the add-on is to create a copy of the script project and publish the copy privately within your Google Workspace Domain. Privately published add-ons do not go through the review process. You can then test the add-on with any account in your domain. Those accounts do not need any access to the script project.

If there is a missing scope or another permission issue, it should be discoverable using the above testing methods.

doubleunary
  • 13,842
  • 3
  • 18
  • 51
  • I find that accounts with edit access to the project get the addon anyway, regardless of whether a test deployment exists or not. And unfortunately I don't have a google workspace domain that I could use. I am surprised there isn't a 'share this addon with some random email' option in apps script for projects that have gone through the verification process already – henryw374 Mar 14 '23 at 07:05
  • If the script project is a [container-bound script project](https://developers.google.com/apps-script/guides/bound), and those secondary accounts are accessing the spreadsheet where you are developing the add-on, what they see is not the test deployment but the "naked" script running in the spreadsheet's context. Create a [standalone script project](https://developers.google.com/apps-script/guides/standalone), then create a test deployment, and enable the test deployment add-on in a spreadsheet that does _not_ have a script project attached. – doubleunary Mar 14 '23 at 07:53
  • ok thanks. using this method, I have been able to test with a non-gmail account (one setup with an existing email address https://support.google.com/accounts/answer/27441?hl=en) and found that MailApp.sendMail does fail silently. – henryw374 Mar 20 '23 at 07:16
0

So, in conclusion, MailApp.sendMail cannot be relied upon for use in an addon, since there is at least one kind of account for which it fails silently (non-gmail account that I have tested with). If there were a MailApp.willEmailWork() method then at least the addon could inform user and disable buttons etc. but using an external mail provider seems like the best route if emails need to be sent.

henryw374
  • 377
  • 4
  • 14