How to Automatically Delete All Emails from a specific Sender on Gmail

Date
Created
May 17, 2025 07:36 AM
Tags
gmail
apps-script
notion image
Are you overwhelmed by emails from a particular sender? Maybe it's an old newsletter or automated alerts you no longer need. If you're looking for a quick, repeatable way to select and delete all emails from a specific address, Google Apps Script can help.
In this post, you’ll learn how to write a simple script that finds all emails from a specific sender and deletes them in bulk—no manual clicking required.

🔧 Step-by-Step: Writing the Script

  1. Open Google Apps Script
      • Click "New Project"
  1. Paste the following code:
function deleteEmailsFromSender() { const senderEmail = "someone@example.com"; // 🔁 Change this to the sender's email const query = `from:${senderEmail}`; const threads = GmailApp.search(query); Logger.log(`Found ${threads.length} threads from ${senderEmail}`); for (let i = 0; i < threads.length; i++) { threads[i].moveToTrash(); // 💥 This deletes the email threads } Logger.log("Finished deleting emails."); }
  • Save the project
    • Click on the filename (e.g., "Untitled project") and name it something like DeleteEmails.
  • Run the Script
    • Click the Run ▶️ button
    • The first time, you’ll be asked to authorize permissions—follow the prompts
  • Check Gmail Trash
    • Go to Gmail and open the Trash folder
    • All emails from the sender should now be there, ready to be permanently deleted

⚠️ A Few Important Notes

  • This script moves emails to Trash, not permanently deletes them. Gmail will auto-delete Trash emails after 30 days, or you can manually empty Trash sooner.
  • Be careful: there’s no “undo” button once emails are moved to Trash!
  • You can schedule this script to run regularly using Triggers (see below).

⏰ Bonus: Automate with a Time Trigger

Want to keep your inbox clean automatically?
  1. In the Apps Script editor, click Triggers (⏰ icon in left sidebar)
  1. Click "+ Add Trigger"
  1. Choose:
      • Function to run: deleteEmailsFromSender
      • Event source: "Time-driven"
      • Set frequency (e.g., daily or weekly)
  1. Click Save
Your inbox will now auto-clean itself on a schedule!

✅ Summary

Using Google Apps Script, you can:
  • Find all emails from a specific address
  • Move them to the Trash in one go
  • Automate the process with a time-based trigger
This is a great way to reclaim your inbox and boost productivity with just a few lines of code.
 
notion image