A script to send mass customizable emails via Gmail API.
warning: if sending from a different email from the previous run, make sure to delete token.json
and replace credentials.json
! To do this, follow the steps in "Credentials Setup".
To mail merge:
- Populate
email-recipients.csv
with one header row, with the strings that are required inemail-text.html
, and the other rows with information. Headers "from", "to", and "subject" are required. (Note that "cc" and "bcc" are not, and the headers are case sensitive.) - Write in
email-text.html
with the HTML of the email. Put to-be-replaced things in brackets, e.g.{num}
. - The script is
emailer.py
.
- try running `emailer.py' directly; it might work!
- go to https://console.cloud.google.com, find the relevant API/project/
- click the "download json" button and move the json into this directory; call it `credentials.json'
- run `emailer.py'; this should give a Google log in screen
- ending screen should be
The authentication flow has completed. You may close this window.
You need these Google things:
- google-api-python-client:
pip install --upgrade google-api-python-client
- google-auth-oauthlib:
pip install google-auth-oauthlib
- Go to console.cloud.google.com, and log in with the desired email.
- Make a new project, or use an arbitrary existing one. Set its location to "No Organization".
- At the OAuth Consent Screen, set the user type to "External" (since you don't have an organization).
- Fill in the app name as "emailer" (or whatever; it doesn't matter), and the support email as your email. No optional fields matter.
- To select scopes, first go to the API library from the OAuth Consent Screen (in a separate tab) and enable the Gmail API. Then, return to the app-registration screen and add the Gmail modify scope:
https://www.googleapis.com/auth/gmail.modify
. - Set yourself as a test user.
- Go to Menu > APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Set the application type as "Desktop App", fill in other fields, and finish.
- Download the JSON file; move it into the emailer directory and rename it
credentials.json
.