Gmail filters allow you to configure a forwarding address, however the emails forwarded:
- Does NOT appear as coming from your own address, and instead shows as if it's from the original sender.
- Does NOT appear in your sent inbox.
This is a problem when forwarding emails to other automated systems (e.g. expense reporting), where the recipient needs to be a known and verified address.
An app script can solve this problem.
The setup is simple:
- Use gmail filters to mark a message to be forwarded using labels
- An app script can then read messages in specified label, forwards them, and change the label to mark the task as complete.
- Setup the script to run every X minutes
- Navigate to Google Apps Script.
- Click
+ New Project
. - This will open the Apps Script editor. Here, paste the code: autoForwardMail.gs.
- Edit the parameters:
forwardingAddress
fromAddress
todoLabelName
completedLabelName
- Save your script with the disk icon or via
File > Save
.
- In the Apps Script editor, find the play icon (
▶️ ) at the top. This will run the chosen function. - Make sure the
developerMode
variable in the script istrue
. This ensures the script only logs actions without performing them. - Click the play button. You'll receive a permissions request.
- Select "Review Permissions", pick your Google account, and grant the required permissions.
- After permissions, run the script once more. Check logged actions via
View > Logs
.
- In the Apps Script environment, click the clock symbol on the left side.
- Click "+ Add Trigger" at the bottom.
- For the function dropdown, choose your function (like
autoForwardMail
). - In the event source dropdown, pick "Time-driven".
- Set how often the script should run (e.g. every 10 min).
- Click "Save".
- If prompted for more permissions for auto-triggering, please provide them.
- Go to Gmail Settings.
- Click "Filters and Blocked Addresses" > "Create a new filter".
- Define your filter criteria (e.g., specific email addresses or subject lines).
- After setting your conditions, click "Create filter".
- On the next page, opt for "Apply the label" and make/select the label as set in the
todoLabelName
parameter in Step 1. - Confirm by clicking "Create filter".
tl;dr: MIT