EasyGmail is a lightweight, minimalistic, and synchronous Python API designed for quick email sending via Gmail.
The current release is a beta release. By stable release 1.0, the following features are projected to be added:
- Unit testing
- Static Site Documentation
- File Attachments
- HTML Emails
- Variadic Recipients
pip install git+https://github.com/ayushgun/easygmail
Before using EasyGmail, ensure you have an app password for Gmail. Do not use your regular account password.
fromeasygmailimportClient, EmailBuilderclient=Client("<address>@gmail.com", "<app password>")
msg=EmailBuilder(
receiver="<recipient>@domain.com", subject="<subject text>", body="<body text>"
).build()
client.send(msg)You can instantiate a Client object in two ways:
- Direct Credentials: Provide email address and app password directly as arguments.
fromeasygmailimportClientclient=Client("<address>@gmail.com", "<app password>")- Environment File:
Use a
.envfile to store credentials.
fromeasygmailimportClientclient=Client(env_file=".env")Your .env file should contain:
EMAIL_ADDRESS="<address>@gmail.com"
PASSWORD="<app password>"Create EmailMessage objects using one of the following methods:
- EmailBuilder Constructor:
fromeasygmailimportEmailBuildermsg=EmailBuilder(
receiver="<recipient>@domain.com", subject="<subject text>", body="<body text>"
).build()- EmailBuilder Factory Interface:
fromeasygmailimportEmailBuildermsg= (
EmailBuilder()
.set_receiver("<recipient>@domain.com")
.set_subject("<subject text>")
.set_body("<body text>")
).build()- Directly Using
EmailMessage:
fromemail.messageimportEmailMessagemsg=EmailMessage()
msg["To"] ="<recipient>@domain.com"msg["Subject"] ="<subject text>"msg.set_content("<body text>")