Skip to content

3ncryptor/MailSender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced Typing Animation

Python Gmail API OAuth2 License

GitHub stars GitHub forks GitHub issues Contributors


About

Production-ready bulk email automation platform built with Python and Gmail API.

Use Cases: Educational institutions, business communications, marketing campaigns, system notifications

Features

Feature Description Status
Bulk Email Processing Send thousands of personalized emails with high throughput Production
Advanced Template Engine Rich HTML/Text templates with dynamic variable substitution Production
CSV Data Integration Flexible data import with intelligent field mapping Production
Intelligent Scheduling Precision time-based campaign execution Production
Fault-Tolerant Retry Logic Configurable retry mechanisms with exponential backoff Production
OAuth2 Security Secure Gmail API authentication with token management Production

System Architecture

Architecture
graph TD
    A[CSV Data Sources] --> B[Template Engine]
    B --> C[Email Generator]
    C --> D[Gmail API Client]
    D --> E[Bulk Sender]
    E --> F[Audit Logger]
    
    G[Config Manager] --> B
    G --> C
    G --> E
    
    H[OAuth2 Auth] --> D
    I[Scheduler] --> E
    J[Retry Handler] --> E
    
    style A fill:#000000,stroke:#00ff41,stroke-width:3px,color:#ffffff
    style E fill:#000000,stroke:#00ff41,stroke-width:3px,color:#ffffff
    style F fill:#1a1a1a,stroke:#ff6b35,stroke-width:2px,color:#ffffff
    style D fill:#1a1a1a,stroke:#007acc,stroke-width:2px,color:#ffffff
Loading

Technology Stack

Tech Stack Animation

Core: Python 3.8+, Gmail API v1, OAuth2
Features: CSV processing, HTML templates, bulk sending, retry logic
Security: Token management, secure authentication, rate limiting

Core Runtime

Python

High-performance application logic with asynchronous capabilities Email Infrastructure

Gmail API

Enterprise-grade email delivery with Google Cloud Platform Security Framework

OAuth2

Industry-standard secure authentication with token lifecycle Scheduling Engine

Schedule

Precision time-based automation with cron-like capabilities Data Processing

CSV

High-throughput data ingestion with intelligent parsing Template System

Templates

Advanced content generation with variable substitution

📁 Project Architecture

Architecture Animation

🏢 MailSender/ (Root Directory)
│
├── 🚀 mailengine/                    ║ Core Email Processing Engine
│   ├── 🔐 auth.py                    ║ → OAuth2 Security & Token Management
│   ├── 📧 send.py                    ║ → Bulk Email Delivery & Retry Logic  
│   ├── 🎨 template_engine.py         ║ → Template Processing & Variable Substitution
│   ├── 📊 logger.py                  ║ → Comprehensive Audit & Logging System
│   └── 🛠️ utils.py                   ║ → Core Utility Functions & Helpers
│
├── ⚙️ config/                        ║ Configuration Management Layer
│   ├── 📋 settings.json              ║ → Campaign Parameters & System Settings
│   └── 📖 readme.md                  ║ → Configuration Documentation
│
├── 📊 csv/                           ║ Data Source Repository
│   ├── 👥 test_participants.csv      ║ → Sample Recipient Database
│   ├── 🎓 GFG_*.csv                  ║ → Educational Campaign Data
│   └── 👨‍🏫 instructors.csv            ║ → Instructor Communication Lists
│
├── 🎨 template/                      ║ Content Management System
│   ├── 🌐 *.html                     ║ → Rich HTML Email Templates
│   └── 📄 *.txt                      ║ → Plain Text Alternatives
│
├── 📎 attachments/                   ║ Media Asset Management
│   └── 📁 campaign_assets/           ║ → Organized File Attachments
│
├── 📋 logs/                          ║ System Monitoring & Analytics
│   └── 📊 mail_log.txt               ║ → Email Delivery Status Reports
│
├── 🎯 mailsender.py                  ║ Application Entry Point & Orchestrator
├── 🔑 credentials.json               ║ Google Cloud Platform API Credentials
├── 🎫 token.json                     ║ OAuth2 Authentication Tokens
└── 📦 requirements.txt               ║ Python Dependency Specifications

🔧 Core Components Overview

🎯 Application Layer

  • mailsender.py - Main orchestrator
  • Campaign scheduling logic
  • Error handling & recovery
  • System initialization

🚀 Processing Engine

  • OAuth2 authentication
  • Email content generation
  • Bulk sending operations
  • Comprehensive logging

📊 Configuration Layer

  • Campaign parameters
  • Template management
  • Data source handling
  • Security credentials

Quick Start Guide

Quick Start Animation

Installation

git clone https://github.com/3ncryptor/MailSender.git
cd MailSender
pip install -r requirements.txt
python -m venv mail-sender-env
source mail-sender-env/bin/activate  # On Windows: mail-sender-env\Scripts\activate

# Install production dependencies
pip install -r requirements.txt

# Verify installation
python -c "import googleapiclient.discovery; print('✅ Gmail API ready')"

📦 Dependencies

Required Python Packages:

Package Version Purpose
google-api-python-client 2.175.0 Google API client library for Gmail integration
google-auth 2.40.3 Google authentication library for OAuth2
google-auth-oauthlib 1.2.1 OAuth2 flow implementation for Google APIs
google-auth-httplib2 0.2.0 HTTP transport adapter for Google authentication
schedule 1.2.2 Job scheduling library for automated campaigns

Manual Installation:

pip install google-api-python-client==2.175.0
pip install google-auth==2.40.3
pip install google-auth-oauthlib==1.2.1
pip install google-auth-httplib2==0.2.0
pip install schedule==1.2.2

3️⃣ Google Cloud Platform Setup

📚 Detailed GCP Configuration
  1. Create Google Cloud Project

    • Navigate to Google Cloud Console
    • Create new project or select existing
    • Note the Project ID for reference
  2. Enable Gmail API

    # Using gcloud CLI (optional)
    gcloud services enable gmail.googleapis.com
  3. Configure OAuth2 Credentials

    • Go to APIs & Services > Credentials
    • Click Create Credentials > OAuth 2.0 Client IDs
    • Select Desktop Application
    • Download JSON file as credentials.json
  4. Security Configuration

    • Add test users if in development mode
    • Configure OAuth consent screen
    • Set appropriate scopes: gmail.send, gmail.readonly

4️⃣ Application Configuration

Create and customize config/settings.json with all available options:

{
  "csv_file": "csv/recipients.csv",
  "template_file": "template/welcome_email.html",
  "subject": "Welcome to Our Platform - {{Name}}",
  "log_file": "logs/campaign_log.txt",
  "default_attachment": "attachments/user_guide.pdf",
  "retry_count": 3,
  "scopes": [
    "https://www.googleapis.com/auth/gmail.send",
    "https://www.googleapis.com/auth/gmail.readonly"
  ],
  "credentials_file": "credentials.json",
  "token_file": "token.json",
  "send_time": "2025-12-15 10:00:00"
}

5️⃣ Data Preparation

# Create recipient CSV file
echo "Name,Email" > csv/recipients.csv
echo "John Doe,john@example.com" >> csv/recipients.csv

# Create basic HTML template
mkdir -p template
cat > template/welcome.html << 'EOF'
<!DOCTYPE html>
<html>
<head><title>Welcome</title></head>
<body>
  <h1>Hello {{Name}}</h1>
  <p>Welcome to our service!</p>
  <p>Your email: {{Email}}</p>
</body>
</html>
EOF

6️⃣ Launch Application

# First run - will trigger OAuth2 flow
python mailsender.py

# Check logs for execution status
tail -f logs/mail_log.txt

Configuration Reference

Configuration Animation

Settings.json Field Reference

Field Type Required Description Example
csv_file string ✅ Yes Path to CSV file containing recipient data "csv/recipients.csv"
template_file string ✅ Yes Path to HTML/text email template "template/welcome.html"
subject string ✅ Yes Email subject line (supports variables) "Welcome {{Name}}!"
log_file string ✅ Yes Path for delivery logs and audit trail "logs/campaign.log"
default_attachment string ❌ No Path to file attached to all emails "files/brochure.pdf"
retry_count integer ❌ No Number of retry attempts for failed sends 3 (default: 1)
scopes array ❌ No Gmail API permission scopes See default scopes below
credentials_file string ❌ No Path to Google API credentials JSON "credentials.json"
token_file string ❌ No Path to OAuth2 token storage file "token.json"
send_time string ❌ No Scheduled send time (ISO format) "2025-12-15 09:00:00"

📝 Complete Configuration Template

{
  "csv_file": "csv/test_participants.csv",
  "template_file": "template/FestDay.html", 
  "subject": "🎉 Event Confirmation - {{Name}}",
  "log_file": "logs/mail_log.txt",
  "default_attachment": "attachments/event_info.pdf",
  "retry_count": 3,
  "scopes": [
    "https://www.googleapis.com/auth/gmail.send",
    "https://www.googleapis.com/auth/gmail.readonly"
  ],
  "credentials_file": "credentials.json",
  "token_file": "token1.json",
  "send_time": "2025-12-15 10:00:00"
}

Usage

python mailsender.py
  "default_attachment": "attachments/feature_guide.pdf",
  "retry_count": 3
}

API

Gmail API Scopes & Permissions

SCOPE PERMISSION USAGE
gmail.send Send emails only Recommended (secure)
gmail.readonly Read email metadata Analytics & reporting
gmail.modify Send + modify emails Advanced workflows
gmail.compose Create draft emails Draft management

🏗️ Programmatic Integration

Python Integration Example:

from mailengine import MailSender
from mailengine.auth import authenticate_gmail

# Initialize the mail sender
mail_sender = MailSender(config_path='config/settings.json')

# Authenticate with Gmail
service = authenticate_gmail()

# Send bulk emails
results = mail_sender.send_bulk_campaign(
    csv_path='data/recipients.csv',
    template_path='templates/welcome.html',
    subject='Welcome to our platform!',
    attachments=['docs/guide.pdf']
)

# Process results
for result in results:
    if result['status'] == 'success':
        print(f"✅ Sent to {result['email']}")
    else:
        print(f"❌ Failed: {result['email']} - {result['error']}")

Command Line Interface:

# Direct execution with custom config
python mailsender.py --config custom_config.json

# Dry run mode (validation only)
python mailsender.py --dry-run

# Verbose logging
python mailsender.py --verbose

# Send specific campaign
python mailsender.py --campaign marketing_q4

🔒 Security Best Practices

🛡️ Credential Security

# Secure file permissions
chmod 600 credentials.json
chmod 600 token.json

# Environment variables
export GMAIL_CREDENTIALS_PATH=/secure/path/
export GMAIL_TOKEN_PATH=/secure/path/

🔐 Access Control

{
  "scopes": ["https://www.googleapis.com/auth/gmail.send"],
  "token_expiry_hours": 24,
  "auto_refresh": true
}

📊 Rate Limiting

{
  "rate_limit": {
    "emails_per_minute": 100,
    "daily_quota": 10000,
    "burst_limit": 50
  },
  "monitoring": {
    "quota_alerts": true,
    "performance_tracking": true
  }
}

🚫 Security Headers

<!-- Email security headers -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">

Troubleshooting

Common Issues:

Issue Solution
Authentication errors Re-run OAuth setup and check credentials
CSV format issues Check Name,Email headers are present
Access denied to credentials Set proper file permissions:
chmod 600 credentials.json
Template errors Verify file paths in settings.json

For debugging, enable "debug": true in settings.json. Run python mailsender.py --health-check for system validation.

Contributing

Contributing Animation

Contributions welcome! Fork repository, create feature branch, follow PEP 8 standards, add tests, and submit pull request.

Quick Start

• Fork and clone repository • Create feature branch: git checkout -b feature/name • Setup environment: python -m venv venv && source venv/bin/activate • Install dependencies: pip install -r requirements.txt

🧪 Development Workflow

Running Tests:

# Run all tests
python -m pytest tests/

# Run specific test category
python -m pytest tests/test_send.py

# Run with coverage
python -m pytest --cov=mailengine tests/

Code Quality:

# Format code
black mailengine/
isort mailengine/

# Lint code  
flake8 mailengine/
pylint mailengine/

# Type checking
mypy mailengine/

License

License

Mail Sender is released under the MIT License

This means you can use, modify, and distribute this software freely, including for commercial purposes, as long as you include the original license notice.


Support

License

Mail Sender is released under the MIT License

Contact & Support

Email: aryanvibhuti@gmail.comGitHub: github.com/3ncryptorIssues: Report BugDiscussions: GitHub Discussions

GitHub stars GitHub forks

99.8% success rate in production • < 2s average processing time per email • 24/7 automated operation capability

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is open source and available under the MIT License.

Support

  • Issues: GitHub Issues
  • Documentation: Check the code comments and examples
  • Email: For support questions

Built by Aryan Vibhuti (3ncryptor)Powered by Gmail API

© 2025 Mail Sender - Bulk Email Automation System

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages