SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Pastimes : All Things Technology - Media and Know HOW

 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext  
From: Don Green3/13/2025 4:35:03 PM
  Read Replies (1) of 2001
 
If you want to clean up your Gmail inbox by deleting emails containing the word "unsubscribe", you can either use Gmail filters (easy, no coding) or a Python script with IMAP (for more control). Here’s how:

Method 1: Using Gmail Filters (No Coding Needed) Gmail has built-in filters that can automatically delete emails containing specific words.

Steps:
  1. Open Gmail and click on the search bar at the top.
  2. Type: unsubscribe and hit Enter to see all emails that contain "unsubscribe."
  3. Click on the filter icon (looks like three sliders) next to the search bar.
  4. In the "Has the words" field, type: unsubscribe
  5. Click Create filter.
  6. Check "Delete it" (this moves the emails to Trash).
  7. Click Create filter again.
?? Note: Gmail only applies filters to new incoming emails, so to delete old ones, manually search "unsubscribe", select all, and delete.

Method 2: Using Python + IMAP to Delete Emails If you want to delete existing emails in bulk, you can use Python with IMAP.

Steps to Run the Script
  1. Enable IMAP in Gmail:

    • Go to Gmail Settings.
    • Under IMAP Access, select Enable IMAP.
    • Click Save Changes.
  2. Generate an App Password (Required if 2FA is enabled):

    • Go to Google App Passwords.
    • Select Mail and Device ? Click Generate.
    • Copy the password (you will need it for the script).
  3. Run the Python Script:

    • Install required libraries if you haven’t: pip install imapclient email
    • Use this Python script:
import imaplib import email # Gmail IMAP Settings IMAP_SERVER = "imap.gmail.com" EMAIL_ACCOUNT = "your_email@gmail.com" EMAIL_PASSWORD = "your_app_password" # Use App Password if 2FA is enabled # Connect to Gmail mail = imaplib.IMAP4_SSL(IMAP_SERVER) mail.login(EMAIL_ACCOUNT, EMAIL_PASSWORD) mail.select("inbox") # Select the inbox folder # Search for emails containing "unsubscribe" status, messages = mail.search(None, 'BODY "unsubscribe"') if status == "OK": for num in messages[0].split(): mail.store(num, "+FLAGS", "\\Deleted") # Mark emails for deletion # Permanently delete emails mail.expunge() mail.close() mail.logout() print("Emails containing 'unsubscribe' have been deleted!") Which Method is Best? ?? Use Gmail filters (Method 1) if you just want to prevent future spam.
?? Use the Python script (Method 2) if you want to bulk-delete old emails automatically.

If you want to clean up your Yahoo Mail inbox by filtering and deleting emails that contain the word "unsubscribe," you can create a Yahoo Mail filter or use IMAP with a Python script.

Method 1: Using Yahoo Mail Filters (No Code Needed) Yahoo Mail has a built-in filtering system that allows you to delete emails automatically.

  1. Log in to your Yahoo Mail account.
  2. Click on the Settings (??) icon in the top right.
  3. Select More Settings.
  4. Click Filters on the left panel.
  5. Click Add new filter.
  6. Give the filter a name (e.g., "Unsubscribe Cleanup").
  7. Under Set rules, choose:
    • "Contains" and type unsubscribe.
  8. Under Choose a folder to move to, select Trash (or create a new folder).
  9. Click Save.
Now, all incoming emails with "unsubscribe" in the content will be moved to Trash.

Method 2: Using Python + IMAP to Delete Emails If you want more control, you can use Python with IMAP to scan and delete emails automatically.

Steps to Run the Script
  1. Enable IMAP in Yahoo Mail:

    • Go to Settings (??) > More Settings > Mailboxes.
    • Click on your Yahoo Mail account and enable IMAP.
  2. Generate an App Password (Yahoo requires this for third-party apps):

    • Go to https://login.yahoo.com/account/security.
    • Click Generate app password.
    • Select Other and copy the password.
  3. Use the following Python script:



python

CopyEdit

import imaplib import email # Yahoo Mail IMAP Settings IMAP_SERVER = "imap.mail.yahoo.com" EMAIL_ACCOUNT = "your_email@yahoo.com" EMAIL_PASSWORD = "your_app_password" # Connect to Yahoo Mail mail = imaplib.IMAP4_SSL(IMAP_SERVER) mail.login(EMAIL_ACCOUNT, EMAIL_PASSWORD) mail.select("inbox") # Search for emails with "unsubscribe" status, messages = mail.search(None, 'BODY "unsubscribe"') if status == "OK": for num in messages[0].split(): mail.store(num, "+FLAGS", "\\Deleted") # Permanently delete flagged emails mail.expunge() mail.close() mail.logout() print("Unsubscribe emails deleted!")
Report TOU ViolationShare This Post
 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext