Skip to main content

email-sender-automation tools built with python

Project description

๐Ÿ“ง Email Sender Automation

Automated bulk email sender built with Python and SMTP. Features recipient management via CSV, dynamic HTML templates with personalisation, configurable send intervals, retry logic, and a full delivery report with success/failure tracking.


๐Ÿ“Œ Table of Contents


๐Ÿ“– About the Project

This is a Python automation project that sends bulk marketing emails using the SMTP protocol. Instead of manually sending emails one by one, this tool reads a list of recipients from a CSV file, personalizes each email using an HTML template, and delivers them automatically โ€” while logging every result.

Built as part of a Python automation portfolio.


โœจ Features

  • โœ… Send bulk emails to hundreds or thousands of recipients
  • โœ… Personalize each email using {{name}} placeholders
  • โœ… Read recipients from a CSV file
  • โœ… HTML email template support
  • โœ… Configurable delay between sends (avoid spam filters)
  • โœ… Retry logic for failed sends
  • โœ… Delivery summary printed to console
  • โœ… Full delivery log saved to sent_log.csv
  • โœ… Failed recipients saved to failed_recipients.csv
  • โœ… Credentials stored securely using .env

๐Ÿ“ Project Structure

email-sender-automation/
โ”‚
โ”œโ”€โ”€ email_sender/                   # Core package
โ”‚   โ”œโ”€โ”€ __init__.py                 # Makes this a Python package
โ”‚   โ”œโ”€โ”€ sender.py                   # Core SMTP send logic
โ”‚   โ”œโ”€โ”€ template_renderer.py        # Renders HTML template per recipient
โ”‚   โ”œโ”€โ”€ logger.py                   # Logs sent/failed results to CSV
โ”‚   โ””โ”€โ”€ config.py                   # Loads .env settings
โ”‚
โ”œโ”€โ”€ data/                           # Input files
โ”‚   โ”œโ”€โ”€ contacts.csv                # recipient list
โ”‚   โ””โ”€โ”€ template.html               # email body template
โ”‚
โ”œโ”€โ”€ output/                         # Auto-generated on run (gitignored)
โ”‚   โ”œโ”€โ”€ sent_log.csv                # Full delivery log
โ”‚   โ””โ”€โ”€ failed_recipients.csv       # Failed sends for re-run
โ”‚
โ”œโ”€โ”€ tests/                          # Unit tests
โ”‚   โ”œโ”€โ”€ test_sender.py
โ”‚   โ””โ”€โ”€ test_template_renderer.py
โ”‚
โ”œโ”€โ”€ main.py                         # Entry point โ€” runs the automation
โ”œโ”€โ”€ .env                            # SMTP credentials (never commit this)
โ”œโ”€โ”€ .env.example                    # Example env file (safe to commit)
โ”œโ”€โ”€ .gitignore                      # Ignores .env, output/, __pycache__
โ”œโ”€โ”€ LICENSE                         # MIT License
โ”œโ”€โ”€ pyproject.toml                  # Build system config
โ”œโ”€โ”€ requirements.txt                # Python dependencies
โ”œโ”€โ”€ setup.py                        # Package setup for PyPI
โ””โ”€โ”€ README.md                       # Documentation (This file)

โš™๏ธ Requirements

  • Python 3.8+
  • A Gmail account (or any SMTP provider)
  • Gmail App Password (if using Gmail with 2FA)

๐Ÿ”ง Installation

  1. Clone the repository
pip install email-sender-automation
  1. Install dependencies
pip install -r requirements.txt
  1. Set up your .env file
cp .env.example .env

Then edit .env with your credentials:

SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SENDER_EMAIL=you@gmail.com
SENDER_PASSWORD=your_app_password_here

๐Ÿ” Configuration

Variable Description Example
SMTP_HOST Mail server address smtp.gmail.com
SMTP_PORT SMTP port (TLS) 587
SENDER_EMAIL Your sending email you@gmail.com
SENDER_PASSWORD App password or SMTP key xxxx xxxx xxxx xxxx

Usage

from email_sender_automation import send_email

send_email(
    subject="Hello",
    body="This is a test email",
    recipients="recipient@example.com"
)
python main.py
python main.py --retry-failed

๐Ÿ“Š Output

After the run completes, you will see a summary in the terminal:

==================================
   EMAIL DELIVERY SUMMARY
==================================
Total recipients : 5000
Sent             : 4873
Failed           : 127
Success rate     : 97.5%
Duration         : 4m 12s
==================================
Log saved to     : output/sent_log.csv
Failed saved to  : output/failed_recipients.csv
==================================

sent_log.csv columns

timestamp recipient subject status error
2025-03-24 09:00:03 alice@example.com Spring Sale! SENT
2025-03-24 09:00:05 bad@@email.net Spring Sale! FAILED SMTPRecipientsRefused

๐Ÿ›ก๏ธ Error Handling

Error What happens
Invalid email address Logged as FAILED, skipped
SMTP timeout Retried up to 3 times
Auth failure Script stops immediately with a clear message
Missing CSV column Script stops immediately with a clear message

๐Ÿ“„ License

MIT License

Copyright (c) 2024 Anuja Khatri

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

Built with Python ยท smtplib ยท Jinja2 ยท python-dotenv

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

email_sender_automation-0.1.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

email_sender_automation-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file email_sender_automation-0.1.0.tar.gz.

File metadata

  • Download URL: email_sender_automation-0.1.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for email_sender_automation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 39abfddca15ef284e301d16fe0c43978138c070d5e8f686d82975f0888140d1a
MD5 9166dfcf952a9e0910b134ee32112ca9
BLAKE2b-256 2b0d625a1d8ff6daf58be6291c1800569a8f7511ec50547d6e8e32cfcb923b95

See more details on using hashes here.

File details

Details for the file email_sender_automation-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for email_sender_automation-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a613293f9ea859390a4608925426b057969ddaf64bab0cacb59b207f117e3f0
MD5 a06ed973d3601124a1000c7f708f2664
BLAKE2b-256 908c81dc6a1edeba4d85a5389d55aed56f8c379a7f7f39a4c47d1fe536012743

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page