Skip to content

Latest commit

 

History

History
60 lines (47 loc) · 1.95 KB

README.md

File metadata and controls

60 lines (47 loc) · 1.95 KB

gmail-manager

Automating some basic Gmail tasks with Python + SMTP

Prerequisites

  • Python 3.x
  • Pip (Python package installer)
  • Virtual Env (Recommended)
python -m venv <env-name>
pip install requirements.txt

Google Cloud Setup

  1. Create a project in the Google Cloud Console.
  2. Following the Quickstart Guide, enable the Gmail API and create OAuth credentials (OAuth client ID) and download the JSON file.

Gmail API Documentation

Note: Check Gmail API Usage Limits first.

Usage

Create data directory, using the test directory as a template

├── data
│   ├── email_message.txt -> email message body
|   ├── emails.csv        -> emails + fields to replace in email message

Create .env file in project directory, add subject and sender email address as environment variables.

SUBJECT="This is my email subject"
EMAIL="sender@gmail.com"

Run script to send an email to each name/email row in emails.csv.

  • All fields enclosed with {{field name}} in email_message.txt must correspond to a column header in emails.csv, with values to replace {{field name}} in the actual email message bodies. This can be used to customize names, specific words in individual emails.
  • -d tag specifies name of data directory described above. Defaults to test/ directory.
python bulk_email_sender.py -d .data

Example

emails.csv:

Email,Name,Project Topics
test@gmail.com,Alice,The Forever Waterbottle

Email will be formatted as shown:

From: <My Email>
Subject: New Project with <Name 1>
To: <Email 1>

Hello {{Name}},
This is a test email! Would you be interested in our new product {{Product Name}}