• Stars
    star
    201
  • Rank 193,713 (Top 4 %)
  • Language
    TypeScript
  • Created about 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bulk unsubscribe from lists in your Gmail inbox for free without compromising privacy

gmail-unsubscribe

This Google Apps Script + Google Spreadsheet combo unsubscribes you from all the messages with a specific label (default "Unsubscribe"). Unlike services such as Unroll.me that sell your data but don't actually work, this script is completely private: all data stays in your Google account, and you can verify the script's behavior by reading its source before giving it access to your account.

Get it here!

Screenshot of the menu

Usage

Run for the first time

  1. Copy the Gmail Unsubscriber to your Google Drive. You'll be able to review the code before creating the copy. This copy, including the code, is completely private to you and can't be accessed or updated by anyone else.
  2. (Optional) To change the labels the script uses, chose "Gmail Unsubscriber > Settings..."
  3. Choose "Gmail Unsubscriber > Create labels". This will create the labels in your Gmail account. Allow the script to access to your Gmail account when prompted.
  4. Open your Gmail inbox, and add the "Unsubscribe" label to some unwanted emails. You can click and drag emails onto the label.
  5. Return to the spreadsheet and choose "Gmail Unsubscriber > Run Now" to unsubscribe from the messages you just tagged. After a few moments, you should see the status of each thread appear in the spreadsheet.

Running automatically

You can choose "Gmail Unsubscriber > Start running" to run the script periodically, even when the spreadsheet is closed.

That way, you can drop new emails into the "Unsubscribe" label whenever you want, and the script will automatically unsubscribe from them.

You can use Gmail filters to automatically add the "Unsubscribe" label to certain kinds of emails or senders, too.

Troubleshooting

If we can't figure out how to unsubscribe from a thread or an error occurs, we'll add a note to the spreadsheet, and re-label the email "Unsubscribe Failed". You can click on the thread's subject to open it in Gmail and unsubscribe manually.

Remove

  • Temporarily disable: choose "Gmail Unsubscriber > Stop running" to stop the script from running automatically.
  • Permanently remove: delete the sheet from your Drive.

How it works

Google Apps Script provides an API that lets us connect to your Gmail account from a Google Sheet. We use that API to query threads with the label "Unsubscribe" (configurable). For each thread, we try several methods to unsubscribe:

  • Emails from reputable lists include a list-unsubscribe header, which is a machine-readable instruction for how to automatically unsubscribe.
    • Ideally the header specifies a mailto: link like mailto:[email protected]?subject=XXXXX that specifies how to unsubscribe from the list by sending an email. If we see this, we sent the unsubscribe email automatically.
    • If the header specifies a web address like https://example.com/unsubscribe?id=XXXXX, we sent an HTTP POST request to that address.
  • If no header is found, we look in the email's HTML body for links that contain the word "unsubscribe". If found, we send an HTTP GET request to that URL. This may not work if they expect you to interact with the page to unsubscribe.

Then, we record the status of the thread in the spreadsheet, and change the label of the thread from "Unsubscribe" to "Unsubscribe Success" or "Unsubscribe Failed" (configurable).

The source code has comments written for beginner programmers if you want to learn more.

Developer info

The software is made of two parts - a Google Sheet for the UI, and the Apps Script source that powers the actions. This repo only contains the Apps Script source, and needs to connect to a Google Sheet to work. We use google/clasp to manage the Apps Script source.

Once you copy the sheet to your account, you can edit the .clasp.json file to point to your copy's ID.

Then, install development dependencies with yarn install or npm install.

To deploy the script to your account, run yarn push or npx clasp push. The first time you do this, clasp will walk you through authorizing your Google Account and enabling the Apps Script API. See the clasp guide for more info.

You can add --watch to the push command to push whenever you edit a file.

Credits

The original 2017 version of gmail-unsubscribe was written by Amit Agarwal. Read the original article here: How to Unsubscribe from Mailing Lists and Junk Newsletters in Gmail.

Jake Teton-Landis rewrote the script to added features and corrected issues that made the original ineffective:

  • Added a "Run Now" button to take action immediately, and reworked menus to show script status and settings.
  • Added "Success" and "Fail" tags for triage within Gmail.
  • Fixed logic mistakes that caused the old version to crash on my emails.
  • Improved error handling. The old version aborted on the first error in any thread with no indication to the user. Combined with the 15 minute schedule, it would take 12 hours to process 100 emails with a failure rate of 50%. Our version will log the error to the spreadsheet and continue to the next thread, cutting the time to ~minutes.
  • The old version assumed that a GET request to a link in the body is sufficient to unsubscribe. We still try by sending a GET request, but these are marked "maybe" in the spreadsheet and moved to the "Fail" label so the user can triage.
  • Improved RFC-compliant handling of the list-unsubscribe header:
    • For http(s): we now including include list-unsubscribe-post body in the request, which is required for one-click unsubscribe, per RFC8058 Section 3.2.
    • For mailto: URLs we now respect the subject and body parameters, which may be needed to identify the user when unsubscribing, as suggested by examples in RFC2369.
  • Written in Typescript, committed to git, pushed to Github, and managed with clasp.

More Repositories

1

Gauss

Stable Diffusion macOS native app
Swift
1,365
star
2

quickjs-emscripten

Safely execute untrusted Javascript in your Javascript, and execute synchronous code that uses async functions
TypeScript
1,248
star
3

monorepo

TypeScript
40
star
4

tlshot

Screenshots + TLDraw
TypeScript
37
star
5

drc-sim-keyboard

control your Wii U with keyboard, mouse, and Xbox 360 controller
Python
36
star
6

memegentino

Meme generator for Notion
TypeScript
21
star
7

GroovesharkDesktop

Userscript-based desktop client for listen.grooveshark.com
JavaScript
21
star
8

media-tools

Home media center automation for filing. uses filebot and beets
Shell
19
star
9

eslint-project-relative

run the right ESlint for your project with syntastic or flycheck.
JavaScript
12
star
10

notrition

Nutrition and recipe integration using the Notion Public API
TypeScript
12
star
11

Dotfiles

Feelin' at home
Perl
10
star
12

ktree

Kotlin implementation of Tree Notation
Kotlin
7
star
13

codenames-redux

barely a codenames implementation in Yavascript
JavaScript
6
star
14

wordpress-pjax

Pjax in Wordpress
JavaScript
6
star
15

Trieste

Dive computer app for Apple Watch
Swift
6
star
16

teeveed

Natural language interface to the media center. Uses wit.ai and jruby
Ruby
6
star
17

music-visualizer-processing

OSC-based music visualizer in Processing
Max
6
star
18

j3

j3 helps your window manager suck a little less. Not for tiling WMs yet :(
Go
6
star
19

fett

boba fett, the slack bot for ordering boba
TypeScript
4
star
20

nodescape

Node graph visualizer in Coffeescript / Three.js / Websockets
JavaScript
3
star
21

pathfinder-tools

Bringing the revolutionary "Ruby Hipster" movement to your D&D game
Ruby
3
star
22

custom-blocks

TypeScript
2
star
23

chopped

chef stuff for fun chef things
Ruby
2
star
24

salty.rb

Unofficial Ruby API for saltybet.com
JavaScript
2
star
25

ts-cli

Straightforward and type-safe command-line argument parsing with subcommands.
TypeScript
2
star
26

chromium-color-emoji-printing-issue

Documentation for https://bugs.chromium.org/p/chromium/issues/detail?id=921585
HTML
2
star
27

ruby-array-trie

Trie-like, prefix-tree data structures that maps from ordered keys to values. Ruby.
Ruby
2
star
28

ear

simple python wrapper around pocketsphinx that listens for it's name. based on Jasper.
Python
2
star
29

mail

mail reader in go+revel, because everyone must write a mail client. It's the law or something.
Go
1
star
30

encabulator

some go projects
Go
1
star
31

py-fingerbank

Python DHCP fingerprinting & tools for using fingerbank's database of DHCP fingerprints
Python
1
star
32

chore-sheets

Generate printable chore sheets for apartment tasks
HTML
1
star
33

dicetower

dice calculator and fairly advanced hubot dice bot thing
JavaScript
1
star
34

go-scripting

Can go be a quick scripting language with help from bash? A library to explore the gradient of options.
Go
1
star
35

tree-of-maps

Experiments with recursive Map structures in Typescript
TypeScript
1
star
36

justbot

IRC bot for Student Affairs - Information Technology at UC Berkeley. Built on Cinch.
Ruby
1
star
37

squidwork

JSON messages and routing over ZeroMQ
Python
1
star
38

RecipiesOnRails

Simple family recipe database to keep Grandma's recipes away from that dangerous borsch. Currently under development.
Ruby
1
star
39

node-screencapturekit

Apple ScreenCaptureKit for NodeJS
Swift
1
star