Reputation: 33
I'm trying to use the GmailApp.sendEmail()
within an Add-on I'm currently working on, and even though I've given it the necessary scopes, it's still failing to send the message with:
"Access denied: : Missing access token for authorization. Request: MailboxService.SendMessage."
Added all scopes needed within the project manifest file:
"oauthScopes" : [
"https://www.googleapis.com/auth/gmail.addons.current.action.compose",
"https://www.googleapis.com/auth/gmail.addons.current.message.metadata",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/script.locale",
"https://mail.google.com/",
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/gmail.compose",
"https://www.googleapis.com/auth/gmail.send",
"https://www.googleapis.com/auth/gmail.addons.current.action.compose",
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/gmail.addons.current.message.metadata"
]
.gs file
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");
GmailApp.sendEmail("[email protected]", "Disclosure Alert", "This message might be sent to the following multiple external domains:");
}
}
Upvotes: 2
Views: 697
Reputation: 389
Add that one : "https://www.googleapis.com/auth/script.send_mail",
I think it's where your error is coming from.
Upvotes: 2