0

I have the following working code which validates a list of recipients based on specific conditions. However, I'm looking to replace the resulting "Logger.log" actions with "Browser.msgbox" actions, and for some reason, GMail App Addons are not allowing me to do so:

function validateRecipients(e) {
  var toEmails = e.draftMetadata.toRecipients, ccEmails = e.draftMetadata.ccRecipients, bccEmails = e.draftMetadata.bccRecipients, domains = [], uniqueDomains = [];
  var allEmails = toEmails.concat(ccEmails, bccEmails);
  for (var i = 0; i < allEmails.length; i++) {
    domains[i] = allEmails[i].split("@").pop().split(".")[0]; 
  }  
  uniqueDomains = domains.filter(listUnique);
  if(uniqueDomains.length <= 2 && uniqueDomains.indexOf("verasafe") != -1) {
    Logger.log("This Message is Good to Go");
  }

  else if(uniqueDomains.length == 0) {
    Logger.log("This Message has no recipients");
  }

  else {
    Logger.log("Please Validate Receipients of this Message and Try again");
  }
}
3
  • 1
    This isn't possible. There is no message box object available to you, and there is not a way of returning an evaluated JavaScript alert script either. Does this have to be a message box? Could you use something like a message in the side-bar? Commented Oct 25, 2019 at 7:00
  • Anything that alerts the user to the outcome, yes - Other than Logger.log Commented Oct 26, 2019 at 13:36
  • It really doesn't seem to be possible. Kind of surprising. An 'Are you sure' dialog box can be pretty essential sometimes - or just the ability to show a card in a popup. Shame :-( Commented Dec 15, 2020 at 22:56

3 Answers 3

3

Partial answer

Browser.msg can't be used on Gmail Add-ons, because, from https://developers.google.com/apps-script/reference/base/browser

This class provides access to dialog boxes specific to Google Sheets.

Sign up to request clarification or add additional context in comments.

2 Comments

Yup, that's my problem :)
Then what is the dialog API we should use to prompt the user with a standard ok/cancel dialog within a GMail add-on (Google script) source?
2

You cannot use Browser.msg or any of the UI classes with Gmail.

However, there is a new feature called Card Service that is meant to be used for the creation of UI for Gmail Addons.

Hope this helps!

Comments

0

The closest I could currently find is notification which shows a quick message at the bottom of the card (in Google's Material design it's called a snackbar

https://developers.google.com/apps-script/reference/card-service/notification

Other than that you need to replace the card with a new one.

function _navigateToCard(card: GoogleAppsScript.Card_Service.Card, replace: boolean)
{
    var nav = CardService.newNavigation();

    replace ? nav.updateCard(card) : nav.pushCard(card)

    return CardService.newActionResponseBuilder()
      .setNavigation(nav)
      .build();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.