How to use Gmail's bulk email sending function?
Most commercial bulk email sending tools cost money, while the quota for free Google email plugins (such as sending emails through Google Forms) is about 50 messages. In fact, the official Gmail API limit is 500 emails per day, which is enough for most individuals. If one account sends too many emails in one day, it will likely be flagged, but 50 is too little. By looping through the Gmail API calls, we can achieve the feat of bulk sending up to 500 emails daily on average.
Let's get started!
Core Goal
Automatically send bulk emails to target Gmail addresses and be able to customize the email content.
Apply for Gmail API
No doubt, to bulk send Gmail emails, you must have a Google account. Go to activate the Google Cloud Console and refer to the figure below to enable the Gmail API. I have already applied for it, so it shows "Manage", accounts that have not applied will prompt "Enable".
Grant Developer App Permissions
Just getting the API Key is not enough to abide by Google's data security policies. To enjoyfully call the API, a developer needs to create an API key, apply for an OAuth 2.0 client, and configure the "consent screen".
Configure consent screen
Let's start with the simplest configuration of the consent screen, here we select "External".
Create API key
Click "Create API Keys" on the page. Then memorize your API key and limit the scope of this key to avoid abuse, such as only for Gmail API calls.
Create OAuth client ID
Click "Create OAuth client ID" on the page. Select Web application as the application type. Fill in "http://localhost:8080/" as the authorized redirect URI.
Download credentials json
After all this is done, Google will give you a credential JSON file. Click "Download JSON" here and save the file to a folder.
Create email project
The design structure of the email project is:
├── image-1.png
├── image-2.png
├── image-3.png
├── new-email.html
├── pure.csv
├── requirements.txt
├── send.py
├── token.json
Email code
The styles in the email are essentially HTML code. The simplest way is to copy a draft from Gmail and paste it into an HTML converter tool to get the source code.
Core Python code
Now summon our powerful Python. The core Python code to send emails via Gmail API is provided.
Target email list format
Target,Status
[email protected],
[email protected],
[email protected],
Run the code
Running the code will automatically pop up a browser window to select your Google account...
Then just need to mindlessly log in and authorize. If all goes well, it will send emails one by one to the addresses provided in the target email list.