Skip to content

mairhythmhoon/email-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

367 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“§ Email Bot - Automated Email Sending System

Python SMTP Google Sheets API Gmail

πŸ€– Intelligent Automated Email Delivery System with Google Sheets Integration

Features β€’ Getting Started β€’ Project Structure β€’ Configuration β€’ Usage β€’ Contributing


πŸ“± Overview

Email Bot is a sophisticated Python-based automation system that seamlessly integrates with Google Sheets to manage and send personalized emails. The system intelligently handles Birthday wishes, Festival greetings, Welcome emails, and Scheduled custom messages with template support, secure delivery, and simplified communication management.

✨ Key Highlights

  • πŸŽ‚ Automatic Birthday Reminders - Never miss a birthday again!
  • πŸŽ‰ Festival Greetings - Send festival wishes automatically
  • πŸ‘‹ Welcome Emails - Personalized welcome messages for new users
  • πŸ“… Scheduled Messages - Custom emails on specific dates
  • πŸ”’ Secure Email Validation - Domain & MX record verification
  • πŸ“Š Google Sheets Sync - Centralized recipient management
  • πŸ“ Template Support - Beautiful HTML email templates
  • πŸ“ˆ Activity Logging - Comprehensive system logs & statistics
  • 🎨 Colorful Console Output - Interactive terminal feedback

πŸš€ Features

Core Capabilities

Feature Description Status
πŸ“Š Google Sheets Integration Fetch recipient data from Google Sheets βœ… Active
πŸŽ‚ Birthday Automation Send birthday greetings on configured dates βœ… Active
🎊 Festival Notifications Automated festival wishes distribution βœ… Active
πŸ“§ HTML Email Templates Customizable email templates with placeholders βœ… Active
πŸ” Email Validation DNS/MX record verification for email addresses βœ… Active
πŸ“‹ Activity Tracking Log all sent emails and system activities βœ… Active
βš™οΈ Environment Configuration Secure credentials management via .env βœ… Active
πŸ›‘οΈ Error Handling Comprehensive exception handling & logging βœ… Active

πŸ“‹ Tech Stack

Languages & Frameworks

Python

Key Libraries

πŸ“¦ python-dotenv      - Environment variable management
πŸ“¦ colorama           - Colorful terminal output
πŸ“¦ dnspython          - DNS resolution for email validation
πŸ“¦ google-auth        - Google authentication
πŸ“¦ google-api-python-client - Google Sheets API integration

Services & APIs

  • 🟒 Google Sheets API - Data source management
  • πŸ“§ Gmail SMTP - Email delivery (smtp.gmail.com:465)
  • πŸ” Google OAuth 2.0 - Secure authentication

πŸ“ Project Structure

email-bot/
β”œβ”€β”€ πŸ“„ task01.py                 # Daily automation task (Birthdays & Festivals)
β”œβ”€β”€ πŸ“„ task02.py                 # Additional email tasks
β”œβ”€β”€ πŸ“„ service.py                # Core service module (Email, Auth, Utils)
β”œβ”€β”€ πŸ“„ requirements.txt          # Python dependencies
β”œβ”€β”€ πŸ“„ .gitignore                # Git ignore rules
β”‚
β”œβ”€β”€ πŸ“ Module/                   # Utility modules
β”‚   β”œβ”€β”€ setup_logger.py          # Logging configuration
β”‚   β”œβ”€β”€ calendar.py              # Festival & birthday filtering
β”‚   └── google_sheet.py          # Google Sheets operations
β”‚
β”œβ”€β”€ πŸ“ Template/                 # HTML email templates
β”‚   β”œβ”€β”€ Birthday_Wishing_Mail.html
β”‚   β”œβ”€β”€ Festival_Mail.html
β”‚   β”œβ”€β”€ Thank_You_Mail.html
β”‚   └── Two_Factor_Authentication.html
β”‚
β”œβ”€β”€ πŸ“ Data/                     # Data storage
β”‚   β”œβ”€β”€ data.json                # Recipients database
β”‚   └── festivals.json           # Festival calendar
β”‚
β”œβ”€β”€ πŸ“ Logs/                     # System logs
β”‚   └── email_bot.log            # Application logs
β”‚
└── πŸ“ Secure/                   # Configuration (⚠️ Not in repo)
    β”œβ”€β”€ credentials.json         # Google Sheet credential file
    └── .env                     # Environment variables

πŸ› οΈ Installation & Setup

Prerequisites

  • Python 3.8 or higher
  • Google Account with Sheets API enabled
  • Gmail Account (for SMTP)
  • Git

Step 1️⃣: Clone the Repository

git clone https://github.com/mairhythmhoon/email-bot.git
cd email-bot

Step 2️⃣: Install Dependencies

pip install -r requirements.txt

Step 3️⃣: Google Sheets API Setup

  1. Go to Google Cloud Console
  2. Create a new project
  3. Enable Google Sheets API and Google Drive API
  4. Create OAuth 2.0 credentials (Service Account)
  5. Download the JSON credentials file
  6. Place it in the Secure/ directory

Step 4️⃣: Environment Configuration

Create a .env file in the Secure/ directory:

# Gmail Configuration
E_MAIL=your-email@gmail.com
PASSWORD=your-app-specific-password
RESPONS_MAILE=your-reply-to@gmail.com

# Google Sheets Configuration
GOOGLE_SHEETS_CREDENTIALS=path/to/credentials.json

⚠️ Important: Generate an App-Specific Password for Gmail if you have 2FA enabled.

Step 5️⃣: Prepare Data Files

Data/data.json

[
    {
        "Name": "John Doe",
        "Email address": "john@example.com",
        "Birthdate": "15/03/1995"
    },
    {
        "Name": "Jane Smith",
        "Email address": "jane@example.com",
        "Birthdate": "22/08/1998"
    }
]

Data/festivals.json

[
    {
        "festival_name": "New Year",
        "date": "01/01/2026"
    },
    {
        "festival_name": "Diwali",
        "date": "01/11/2026"
    }
]

πŸš€ Usage

Run Daily Automation Task

python task01.py

This will:

  • πŸ” Fetch recipient data from Google Sheets
  • πŸŽ‚ Check for birthdays and send wishes
  • πŸŽ‰ Check for festivals and send greetings
  • πŸ“Š Log activities to Google Sheets
  • πŸ“ Generate system logs

Run Additional Tasks

python task02.py

Schedule Automated Runs

On Linux/Mac (using cron):

# Edit crontab
crontab -e

# Add this line to run daily at 8 AM
0 8 * * * cd /path/to/email-bot && python task01.py

On Windows (using Task Scheduler):

  1. Open Task Scheduler
  2. Create a new task
  3. Set trigger: Daily at 8:00 AM
  4. Set action: Execute python.exe with argument C:\path\to\task01.py

πŸ“§ Email Templates

The system supports customizable HTML email templates with dynamic placeholders:

  • {name} - Recipient's name
  • {festival} - Festival name

Example Template Structure

<html>
  <body>
    <h1>Hello {name}! πŸŽ‰</h1>
    <p>Wishing you a wonderful {festival}!</p>
  </body>
</html>

πŸ” Security & Best Practices

Credential Management

  • βœ… Use environment variables (.env file)
  • βœ… Never commit .env to Git
  • βœ… Use Gmail App-Specific Passwords (not your main password)
  • βœ… Keep credentials.json private

Email Validation

  • βœ… Regex pattern validation
  • βœ… MX record verification
  • βœ… Domain existence checking
  • βœ… Automatic error logging

Error Handling

  • βœ… Comprehensive try-catch blocks
  • βœ… Detailed logging system
  • βœ… Graceful failure recovery

πŸ“Š Activity Tracking

Logged Metrics

  • πŸ“ˆ Total emails sent
  • πŸŽ‚ Birthday emails count
  • πŸŽ‰ Festival emails count
  • ❌ Failed delivery attempts
  • ⏰ Execution timestamps

Output Logs

[2026-04-24 08:30:15] INFO: EMAIL SYSTEM STARTED
[2026-04-24 08:30:16] INFO: Fetching Data From Database
[2026-04-24 08:30:18] INFO: Birthday Today: John Doe
[2026-04-24 08:30:20] INFO: Email sent to john@example.com
[2026-04-24 08:30:21] INFO: EMAIL SYSTEM ENDED

πŸ› Troubleshooting

Issue Solution
Gmail authentication fails Ensure App-Specific Password is used, not your main password
Invalid email format error Check email format in data.json
MX record lookup fails Verify internet connection, domain may not exist
Google Sheets not syncing Verify credentials.json and API permissions
Templates not loading Ensure template files exist in Template/ directory
No emails sent Check if dates in data.json match today's date

πŸ“ Logging & Debugging

View detailed logs in Logs/email_bot.log:

# View last 20 lines
tail -20 Logs/email_bot.log

# Watch logs in real-time
tail -f Logs/email_bot.log

🀝 Contributing

Contributions are welcome! Here's how to help:

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

Areas for Contribution

  • πŸ“§ Additional email templates
  • 🎨 Enhanced HTML designs
  • 🌍 Internationalization (multi-language support)
  • ⚑ Performance optimizations
  • πŸ“± SMS notification support

πŸ“š Documentation

Module Details

service.py - Core service module

  • Email sending functionality (SMTP)
  • Template loading and management
  • Email validation with DNS lookup
  • Google Sheets integration
  • Logging and activity tracking

task01.py - Daily automation task

  • Birthday checking and filtering
  • Festival notification logic
  • Statistics generation
  • Google Sheets data sync

task02.py - Additional email operations

  • Custom scheduled emails
  • Bulk email sending
  • User management tasks

πŸ“ž Contact & Support

Get in Touch


πŸ“œ License

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

License: MIT

πŸ’‘ Future Enhancements

  • Advanced scheduling with cron expressions
  • Multi-language template support
  • User preference management
  • Automated email list segmentation

⭐ If you found this project helpful, please consider giving it a star!

Built with ❀️ by mairhythmhoon


Last Updated: April 24, 2026

About

Automated Email Sending System integrated with Google Sheets to synchronize recipient data and send scheduled emails for birthdays, festivals, and welcome messages.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors