• Stars
    star
    131
  • Rank 274,276 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created 9 months ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight, minimalistic, and synchronous Python package for quickly sending emails via Gmail.

EasyGmail

Overview

EasyGmail is a lightweight, minimalistic, and synchronous Python API designed for quick email sending via Gmail.

Roadmap

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

Getting Started

Installation

pip install git+https://github.com/ayushgun/easygmail

Prerequisites

Before using EasyGmail, ensure you have an app password for Gmail. Do not use your regular account password.

Quick Start Example

from easygmail import Client, EmailBuilder

client = Client("<address>@gmail.com", "<app password>")

msg = EmailBuilder(
    receiver="<recipient>@domain.com", subject="<subject text>", body="<body text>"
).build()

client.send(msg)

Client Initialization

You can instantiate a Client object in two ways:

  1. Direct Credentials: Provide email address and app password directly as arguments.
from easygmail import Client

client = Client("<address>@gmail.com", "<app password>")
  1. Environment File: Use a .env file to store credentials.
from easygmail import Client

client = Client(env_file=".env")

Your .env file should contain:

EMAIL_ADDRESS="<address>@gmail.com"
PASSWORD="<app password>"

Creating Email Messages

Create EmailMessage objects using one of the following methods:

  1. EmailBuilder Constructor:
from easygmail import EmailBuilder

msg = EmailBuilder(
    receiver="<recipient>@domain.com", subject="<subject text>", body="<body text>"
).build()
  1. EmailBuilder Factory Interface:
from easygmail import EmailBuilder

msg = (
    EmailBuilder()
    .set_receiver("<recipient>@domain.com")
    .set_subject("<subject text>")
    .set_body("<body text>")
).build()
  1. Directly Using EmailMessage:
from email.message import EmailMessage

msg = EmailMessage()
msg["To"] = "<recipient>@domain.com"
msg["Subject"] = "<subject text>"
msg.set_content("<body text>")