开发可独立显示的Gmail Add-on:功能实现及清单配置问询
Absolutely, every part of your request is completely achievable with Gmail Add-ons and the Gmail API:
- Reading multiple emails: You can use the Gmail API's
Users.Messages.listorUsers.Threads.listmethods to fetch batches of emails (with filters like label, date range, etc.) directly from the user's inbox—no need to open individual messages first. - Creating labels & filters: The Gmail API provides dedicated endpoints (
Users.Labels.createfor labels,Users.Settings.Filters.createfor filters) that your add-on can call to create these items programmatically. - Always visible (no need to open emails): You can configure your add-on to load directly in Gmail's right-hand sidebar when the user is on the inbox, label views, or other main Gmail screens—no need to open a single email first.
appsscript.json) Configurations Your manifest file needs specific entries to enable these features. Here's what you'll need to define:
1. OAuth Scopes
You'll need to request the necessary permissions for your add-on to interact with Gmail data and settings. Add these to the oauthScopes array:
"oauthScopes": [ "https://www.googleapis.com/auth/gmail.readonly", "https://www.googleapis.com/auth/gmail.modify", "https://www.googleapis.com/auth/gmail.settings.basic" ]
gmail.readonly: Lets your add-on read email metadata and content.gmail.modify: Permits creating/modifying labels and updating email properties.gmail.settings.basic: Required for creating email filters.
2. Homepage Trigger (For "Always Visible" Behavior)
This trigger makes your add-on load in the sidebar whenever the user is on a main Gmail screen (inbox, label pages, etc.). Add this to your manifest:
"homepageTrigger": { "runFunction": "renderAddonHomepage", "enabled": true }
renderAddonHomepageis the name of a server-side Apps Script function you'll write to generate the add-on's UI (using CardService) for the homepage view.
3. Universal Action (Optional, for Quick Access)
If you want to add a prominent button in Gmail's top bar to open your add-on, include a universalActions entry:
"universalActions": [ { "label": "Open Email Manager", "runFunction": "renderAddonHomepage" } ]
4. Gmail Add-on Core Configuration
Define basic details for your add-on under the gmail field:
"gmail": { "name": "My Email Manager Add-on", "logoUrl": "https://your-domain.com/addon-logo.png", "primaryColor": "#4285F4", "secondaryColor": "#34A853", "contextualTriggers": [] }
- Leave
contextualTriggersempty since you don't need the add-on to trigger only when opening individual emails.
5. Advanced Services Dependency
Since you'll be using the Gmail API directly, declare it as an enabled advanced service:
"dependencies": { "enabledAdvancedServices": [ { "userSymbol": "Gmail", "serviceId": "gmail", "version": "v1" } ] }
- Permission Minimization: Make sure you only request the scopes you actually need—Google's add-on review process will scrutinize unnecessary permissions.
- Pagination for Emails: When fetching multiple emails, handle the
nextPageTokenfrom the Gmail API to load more results if the user's inbox has a large number of messages. - UI Building: Use Google's CardService to create interactive components (like email lists, label creation forms, filter setup inputs) for your add-on's sidebar.
内容的提问来源于stack exchange,提问作者user1410569

