My gmail was filled with OTP mails (mainly from erp iitkgp) and it was kinda annoying
- First clone the repo
- Create a
.envfile and set it up using.env.template(this is the most important part)
TARGET_MAIL= Your full Gmail address.TARGET_MAIL_APP_PASSWORD= This is a 16-character password. To get this, turn on 2-Step Verification in your Google Account settings, then go to App Passwords to generate one.TARGET_SUBJECT= The text to search for, e.g., "OTP for Sign In in ERP Portal of IIT Kharagpur". (It matches any email with subject containing this text).TARGET_DAYS= Set this tonto delete emails from the lastndays only (n = any integer)
- Run the script
go run main.go
- For the script to instantly remove emails from your Inbox, you must ensure Gmail's "Auto-Expunge" is enabled.
- Open Gmail in your browser.
- Go to Gmail Settings > Forwarding and POP/IMAP.
- Under IMAP Access, find Auto-Expunge.
- Make sure it is set to "Auto-Expunge on - Immediately update the server".
- This script acts safely: It moves matching emails to the Trash folder; it does not permanently delete them immediately. If you accidentally delete something important, you can restore it from the Trash within 30 days (before Gmail permanently removes it).