I’m trying to build an in-house Gmail add-on to handle incoming emails and let users interact with our company software. But I’m stuck on how to use OAuth 2.0 for this.
I’ve looked everywhere for info on Gmail Contextual Gadgets with OAuth 2.0, but no luck. The old examples use OpenID, which isn’t allowed anymore.
I’m not sure how to set this up or deploy it just for our domain. The Google Apps Extensions Console seems outdated, and the new Developers Console is confusing.
When I try to deploy, I get an error about OAuth 1.0 not being available. But I never used that version!
Has anyone successfully made a Gmail add-on recently? Is it even possible now? How do you handle the OAuth 2.0 part?
Here’s a simple code example of what I’m trying to do:
function processEmail(emailData) {
// Get email content
var subject = emailData.getSubject();
var body = emailData.getPlainBody();
// Do something with the email
var result = ourCompanyAPI.processEmailContent(subject, body);
// Update UI
updateAddOnInterface(result);
}
I’ve successfully implemented a Gmail add-on recently, and I can confirm it’s still possible with OAuth 2.0. The key was leveraging Google Apps Script alongside the Gmail API. I set up a project in the Google Cloud Console, enabled the Gmail API, and wrote my add-on code in Apps Script. I implemented the necessary triggers, such as onGmailMessage, and deployed the add-on via the Google Workspace Marketplace SDK. With Apps Script handling most of the OAuth complexity, ensuring the correct scopes in the manifest file and thorough testing in the editor proved essential.
I’ve recently gone through a similar process, and I can tell you it’s definitely still possible to create custom Gmail add-ons with OAuth 2.0. The key is to use the Google Apps Script platform, which handles a lot of the OAuth complexities for you.
First, you’ll need to create a new project in the Google Cloud Console and enable the Gmail API. Then, in Google Apps Script, you can create your add-on code and use the Gmail service without explicitly dealing with OAuth tokens.
For deployment, use the new Google Workspace Marketplace SDK in the Google Cloud Console. It’s much more straightforward than the old process.
Your code example looks good, but you’ll need to wrap it in the appropriate Gmail add-on event handlers. Something like:
function onGmailMessage(e) {
var accessToken = e.messageMetadata.accessToken;
GmailApp.setAccessToken(accessToken);
var messageId = e.messageMetadata.messageId;
var message = GmailApp.getMessageById(messageId);
processEmail(message);
}
This approach has worked well for our internal add-ons. Hope this helps point you in the right direction!
yeah, its totally doable. i made one last month using google apps script. the tricky part was setting up the cloud console stuff, but once thats done its pretty smooth sailing. just make sure u use the right scopes in ur manifest file and test a bunch in the editor. dont forget to use onGmailMessage() as ur main trigger function