The Automated Email Unsubscriber is a Python project designed to help you automatically unsubscribe from unwanted emails in your Gmail account. It uses the Gmail API for secure access, Natural Language Processing (NLP) for analyzing emails, and automation techniques to process unsubscribe requests.
- Features
- Project Structure
- Prerequisites
- Installation
- Usage
- Dependencies
- Potential Issues and Solutions
- License
- Acknowledgments
- Contact
- Gmail API Integration: Secure OAuth 2.0 authentication to connect to Gmail.
- Email Parsing: Extracts sender, subject, body, and headers from emails.
- Unsubscribe Detection: Detects unsubscribe links or instructions using NLP (supports English and Russian).
- Automated Unsubscription: Automates the process of visiting unsubscribe links or sending unsubscribe emails.
- Language Detection: Identifies the email's language to apply appropriate NLP models.
- Respectful Request Handling: Implements delays to avoid overwhelming servers.
automated-email-unsubscriber/
├── email_message_wrapper.py # Parses email messages.
├── gmail_client.py # Handles Gmail API interactions.
├── main.py # Main script to run the program.
├── README.md # This README file.
├── requirements.txt # Python dependencies list.
├── unsubscribe_detector.py # Detects unsubscribe links.
├── unsubscriber.py # Automates the unsubscription process.
└── utils.py # Utility functions.
- Python: Version 3.8 or higher.
- Google Account: A Gmail account with Gmail API access enabled.
- Internet Connection: Required for downloading models and API access.
-
Clone the Repository:
git clone https://github.com/yourusername/automated-email-unsubscriber.git cd automated-email-unsubscriber
-
Create a Virtual Environment (Optional but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
-
Download SpaCy Language Models:
python -m spacy download en_core_web_sm python -m spacy download ru_core_news_sm
-
Set Up Google API Credentials:
- Enable Gmail API:
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to APIs & Services > Library.
- Search for "Gmail API" and click Enable.
- Create OAuth 2.0 Credentials:
- Navigate to APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Select "Desktop app" as the application type.
- Download the
credentials.json
file. - Place the
credentials.json
file in the project directory.
- Enable Gmail API:
-
Authenticate with Gmail:
- Run the script for the first time:
python main.py
- A browser window will open for Google account login. Grant the necessary permissions. Authentication tokens will be saved in
token.pickle
for future use.
- Run the script for the first time:
-
Run the Script:
python main.py
The script will:
- Fetch emails from your Gmail account.
- Detect unsubscribe instructions.
- Attempt to unsubscribe from unwanted emails.
- Log the results in the console.
-
Monitor the Output:
- Check the console for details about:
- Emails processed.
- Unsubscribe links found.
- Unsubscription attempts and their success status.
- Check the console for details about:
The dependencies are listed in requirements.txt
:
beautifulsoup4==4.12.2
google-api-python-client==2.94.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
langdetect==1.0.9
requests==2.31.0
spacy==3.6.1
transformers==4.33.3
Install them with:
pip install -r requirements.txt
- Warning Message:
NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'
- Cause: Python’s SSL module is compiled with an older LibreSSL version.
- Solutions:
- Upgrade SSL Libraries:
- Install OpenSSL 1.1.1+ and recompile Python with the updated version.
- Temporarily downgrade
urllib3
:pip install 'urllib3<2'
- Upgrade SSL Libraries:
- Issue: NLP models fail to download.
- Solution:
- Ensure a stable internet connection.
- Retry downloading or manually download the models using SpaCy's CLI.
This project is licensed under the MIT License.
- Google Gmail API: For providing access to Gmail functionalities.
- SpaCy: For NLP capabilities.
- Hugging Face Transformers: For zero-shot classification models.
- Beautiful Soup: For parsing HTML content.
For questions or suggestions, reach out to:
- Svetlana Perekrestova
Email: svetlana.perekrestova2@gmail.com