This repository contains a local Python application for automating personalized email campaigns via Gmail. It provides a command‑line interface (CLI) to send initial outreach emails, schedule follow‑up messages, and track all sends and status in a local SQLite database.
- One‑off email sending: Send a templated first email to a list of contacts.
- Automated follow‑ups: Define multiple follow‑up drafts and delays; send them conditionally based on contact settings.
- Toggle per‑contact: Enable or disable follow‑up sequences on a per‑recipient basis.
- Tracking & logging: All sent messages (initial and follow‑ups) are recorded with timestamp and status in SQLite.
- Dry‑run mode: Preview which emails would be sent without actually transmitting.
- Customizable templates: Store email bodies as plain text with
{{placeholder}}tokens.
-
Language: Python 3.9+
-
Database: SQLite (via the built‑in
sqlite3module) -
Templating: Jinja2 or Python’s
string.Template -
Email transport:
- Option A: Gmail SMTP (
smtplib+ App Password) - Option B: Gmail API (
google-api-python-client+ OAuth2)
- Option A: Gmail SMTP (
-
CLI framework:
argparse(built‑in) orclick -
Dependencies: Listed in
requirements.txt
email-automation/
├── send.py # Main CLI entry point
├── db.py # Database schema and helper functions
├── templates/ # Email template files
│ ├── initial_email.txt # First outreach message
│ ├── followup_1.txt # Follow‑up #1 message
│ └── followup_2.txt # Follow‑up #2 message
├── email_db.sqlite # Local SQLite database (auto‑generated)
├── credentials/ # OAuth2 tokens or App Password storage
│ └── gmail_creds.json
├── requirements.txt # Python dependencies
└── README.md # This documentation
-
Python 3.9 or higher installed
-
Gmail account with one of the following:
- App Password (recommended for simplicity)
- OAuth2 credentials (requires Google Cloud Project setup)
-
Access to a terminal/console on your local machine
-
Clone this repository:
git clone https://github.com/<your‑username>/email-automation.git cd email-automation
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
-
SMTP + App Password:
-
Enable 2‑Step Verification on your Google Account.
-
Generate an App Password for “Mail.”
-
Save it in
credentials/gmail_creds.json:{ "email": "you@gmail.com", "app_password": "abcd efgh ijkl mnop" }
-
-
Gmail API + OAuth2 (optional):
- Create a Google Cloud Project with Gmail API enabled.
- Download
credentials.jsonfrom OAuth2 consent setup. - Place it in
credentials/and follow the first‑run instructions insend.pyto generate tokens.
Convert your contacts spreadsheet to CSV and load into the database:
python send.py --import contacts.csvThis will populate contacts table with name, email, and default settings.
python send.py --send --step 0Sends the first template (initial_email.txt) to all contacts with step = 0.
python send.py --send --step 1
python send.py --send --step 2Sends follow‑up #1 or #2 to contacts whose step matches and whose followups_enabled flag is true, provided the configured delay has elapsed.
python send.py --dry-run --send --step 0Prints which emails would be sent, without actually sending.
Use the CLI to enable/disable follow‑ups for a specific contact:
python send.py --toggle-followup --email alice@example.com --off- contacts (
id,name,email,followups_enabled,step,last_sent) - log (
id,contact_id,template,timestamp,status)
Contributions welcome! Feel free to open issues or submit pull requests.