寻求适配Google Inbox的自动转发脚本替代方案
Great question—since Google Inbox doesn’t support custom labels like Gmail does, we need to work with its native features and adjust your script to use alternative targeting methods. Here are a few solid approaches to implement auto-forwarding without labels:
Option 1: Target Emails via Search Queries (Sender, Subject, Keywords)
Google Inbox uses Gmail’s underlying search syntax, so you can directly target emails using criteria like sender, subject, or keywords. To avoid re-forwarding the same emails, you can mark threads as "Done" (a core Inbox feature) after processing—this removes them from your main Inbox view and ensures they won’t be picked up in future runs.
Here’s the adjusted script:
function autoForwardInbox() { var recipient = 'domain@forward.domain.com'; var interval = 5; // Match your trigger interval (minutes) var date = new Date(); date.setMinutes(date.getMinutes() - interval); // Customize this search query to target your desired emails // Example: Emails from "client@example.com" received in the last 5 mins, not marked as Done var searchQuery = `from:client@example.com after:${Math.floor(date.getTime()/1000)} is:undone`; var threads = GmailApp.search(searchQuery); threads.forEach(thread => { // Forward the entire thread to your recipient thread.forward(recipient); // Mark as Done to prevent re-forwarding thread.markAsDone(); }); }
You can tweak the search query to fit your needs:
- Use
subject:"Urgent Request"to target specific subject lines - Use
has:attachmentto forward emails with files - Use
is:inboxto target only emails in your main Inbox view
Option 2: Target Emails in a Specific Inbox Bundle
Inbox bundles (like "Work", "Promotions", or custom bundles) map to hidden system labels in Gmail. You can use these labels in your search query to target all emails in a specific bundle.
To find the exact label name for your bundle:
- Open the regular Gmail interface (Inbox shares Gmail’s backend)
- Check the left-hand labels list—your custom Inbox bundles will appear here
Adjust the search query in the script above to use the bundle’s label:
// Example: Target emails in the "Work" bundle, received in the last 5 mins var searchQuery = `label:work after:${Math.floor(date.getTime()/1000)} is:undone`;
Option 3: Track Forwarded Emails with Custom Properties (Keep Emails in Inbox)
If you don’t want to mark emails as "Done" (e.g., you need to keep them in your Inbox), you can store the IDs of forwarded threads in Google’s Properties Service to avoid duplicates.
Here’s the script for this approach:
function autoForwardInbox() { var recipient = 'domain@forward.domain.com'; var interval = 5; var date = new Date(); date.setMinutes(date.getMinutes() - interval); // Target emails (adjust query as needed) var searchQuery = `after:${Math.floor(date.getTime()/1000)} is:inbox`; var threads = GmailApp.search(searchQuery); // Load already forwarded thread IDs var userProperties = PropertiesService.getUserProperties(); var forwardedThreads = userProperties.getProperty('forwardedThreads') || ''; var forwardedIds = new Set(forwardedThreads.split(',').filter(id => id)); threads.forEach(thread => { var threadId = thread.getId(); if (!forwardedIds.has(threadId)) { thread.forward(recipient); // Add the thread ID to our tracked list forwardedIds.add(threadId); userProperties.setProperty('forwardedThreads', Array.from(forwardedIds).join(',')); } }); }
Final Setup Note
Don’t forget to set up a time-driven trigger in Google Apps Script to run your function every 5 minutes—just like you did for your original Gmail script. This ensures the script checks for new emails on a regular basis.
内容的提问来源于stack exchange,提问作者JoaMika

