Simple tool to take a CSV and a template and create drafts in your Gmail. Can be used as a command line tool, or as a library.
Project description
Gmail Drafter: Create Mail Merge Drafts
Simple tool to take a CSV and a template and create drafts in your Gmail. Useful for sending emails to large-ish numbers of people where you want to slightly customize the emails for each user. You can quickly run through drafts, customize it, and send.
Installation
pip install -U gmail-draft-creator
Usage
Usage: gmail-draft-creator [OPTIONS]
Options:
--csv PATH Path to the CSV file. [required]
--template PATH Path to the template file. [required]
--subject TEXT Subject for the email drafts.
--dry-run Run script without creating drafts.
--help Show this message and exit.
You can also import the create_draft
function and use it in your own scripts.
CSV Files
Must contain an email
column (case insensitive).
Each column in the CSV is passed as a parameter to the provided template. The column name is stripped of whitespace, lowercased, and stripped all non-alpha characters. For example, a column named First Name
would be passed as $firstname
in the template.
Template Files
You can include subject line and variables in the template file:
Subject: Hello $NAME
Hi, here's another ${REASON} why I'm emailing you.
CSV Files
A CSV file that would work with this template might be something like this:
Email,Name,Reason,OtherColumn,...
joe@test.com,Joe,reminder,...
jeff@email.com,Jeff,sales pitch,...
Setup
You need to create a "OAuth 2.0 Client IDs" which has to be done with a Google Workspace (gsuite). This will not work on a personal gmail account (unless you create a app on a workspace and add your personal account as a test account).
Generating a Gmail API Token
- Navigate to the Google Cloud Console. https://console.developers.google.com/
- Create a new project or select an existing one.
- Go to "APIs & Services" -> "Library" and enable the Gmail API.
- Navigate to "APIs & Services" -> "Credentials".
- Click "Create Credentials" -> "OAuth client ID".
- Select "Desktop app" as the application type, then click "Create".
- Download the JSON file, rename it to
credentials.json
, and place it in the root of this project. - Run the script and oauth into your account
If you want to edit scopes on an existing application, you can:
- OAuth Consent Screen
- Edit
- Continue to step 2
- Add or remove scopes
- Add scopes and save
Credential Scopes Needed
Two main scopes are required for this:
https://www.googleapis.com/auth/gmail.compose
https://www.googleapis.com/auth/gmail.readonly
Some other scopes I'd add so you can reuse the credentials in other projects, like gmailctl or calendar scripts:
https://www.googleapis.com/auth/calendar.readonly
https://www.googleapis.com/auth/calendar.event
https://www.googleapis.com/auth/gmail.labels
https://www.googleapis.com/auth/gmail.settings.basic
TODO
- add credentials as a command line argument
- add serialized token as a CLI argument
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
Built Distribution
File details
Details for the file gmail_draft_creator-1.3.1.tar.gz
.
File metadata
- Download URL: gmail_draft_creator-1.3.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/6.5.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eb23ab29ea40f78e101113fa3a14ace97b33cac276a6f7726cacd7c6507cfb4 |
|
MD5 | 05438613395985d7ca0fe11849e342ed |
|
BLAKE2b-256 | 8203819c39ebd60f6912a7b0969ef88fa98f9ec75e256ca37f73d27730a42418 |
File details
Details for the file gmail_draft_creator-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: gmail_draft_creator-1.3.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/6.5.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1243b50319810f5c3f553db6ac2204a1804860cac43ce663c21cbbf32000d584 |
|
MD5 | 32daef66ab5b3925f6f4e1c431708343 |
|
BLAKE2b-256 | 52d75cf962bf55e89448a37a1847e22cb5ccbee150317ff7e6d7a521ff6bca61 |