GMail Attachments Remover is a small Google Apps Script that will essentially remove the attachment from any e-mail you select in Gmail -- hence saving precious space in a 15Go limited world. More in details, removing attachments is not an existing feature in the email protocole, however this script will create its best possible replica, then Trash the original email, living in place an email with attachments of each 0Kb.
See for yourself: ToDo: Insert before-after picture
- Follow the instructions below
- Run the script once, it will create the Labels _TooBigEmails and _FormerBigEmails
- Add the threads you want to clean to _TooBigEmails
- Run the script, it will "remove" the attachments, add the _FormerBigEmails label on the new email, and place the old email of the email to Trash
- Check everything is Ok with the copies in _FormerBigEmails
- (Optional) Empty trash
- If too many emails, the script can timeout. A simple re-run will help. Note that technically, it could create one too many copies of a cleaned email if it crashes after the copy and before the Trashing.
- UI isn't pretty in the Gmail Add-on
- The GMail Add-on cannot reload the GMail tab, so unfortunately you'll have to reload manually to see the effects once the script finished running.
First install npm, on Debian based with
sudo apt get npm
Then clasp:
npm install -g @google/clasp
clasp login
If you use a proxy:
HTTP_PROXY=xxxx HTTPS_PROXY=xxxx clasp login
- Go to https://script.google.com/home/usersettings
- Turn Google Apps Scripts API "on"
git clone licryle/GmailAttachmentsRemover
cd GmailAttachmentsRemover/
clasp create --title GmailAttachmentsRemover --type Standalone --rootDir .
To be able run the script, you need to create a new Google Cloud (GCP) project.
Note that for the rest of the instructions, I will assume you stick to naming thr GCP Project GmailAttachmentsRemover.
Most clickable links will be broken otherwise. Only change the name if you know what you're doing.
- Create a GCP project -- Full Doc - Use GmailAttachmentsRemover as name
- Copy the project id from the Project details.
clasp setting projectId xxxx
- Configure a Consent Screen in Branding -- App Name: GmailAttachmentsRemover -- Email: input your email -- Audience: Internal if you're in a workspace, External otherwise
- Create a credentials / OAuth client ID in Clients -- Application Type: Desktop App -- Name: MyDevStation or whatever you wish to name your computer's credentials -- Click CREATE -- Then DOWNLOAD JSON to the ./ directory -- Rename the file to creds.json
- Add yourself as a test user in Audience -- Under Test users, Add users -- Add your gmail on which you want to run the script -- Save
- Verify your credentials and everything works with the command
clasp login --creds creds.json- It will take to through the Google Authentication consent flow in the UI; make sure to click Continue, which is not the attractive/blue/highlighted option by default, since it's a "dangerous" program under development (of which, technically, you act as the developer).
clasp apis enable gmail
This will ensure you can easily remove attachments from an EMail directly from the UI of Gmail, as well as trigger the whole clean-up.
clasp open- Click on the dropdown arrow next to the Deploy button
- Click Test deployments
- Under Google Workspace Add-on, you should see Application(s)
- Click Install next to Gmail
Open or reload your Gmail browser tab, and should should see the icon on the Right hand bar.
At this stage, the program should run, either in the UI:
clasp open- Select main.gs
- Select function main
- Click Run
clasp run main
On the right hand bar of Add ons -- if you installed the add-on -- will appear.