Skip to main content

Send and read emails easily — with attachments, inline images, HTML templates, and OAuth2 authentication.

Project description

📧 EzMail

Send and read emails easily — with attachments, inline images, HTML templates, and OAuth2 authentication.

ezmail is a modern Python library that simplifies email automation. It allows you to send and receive emails via SMTP and IMAP, supporting advanced features such as inline images, HTML content, file attachments, and secure authentication (TLS or OAuth2).


🚀 Features

✉️ Sending Emails (EzSender)

  • Send emails to one or multiple recipients
  • Support for both HTML and plain text bodies
  • Add inline images directly into the message
  • Attach any type of file (PDF, CSV, XML, etc.)
  • Use Jinja2 templates for dynamic HTML emails
  • Secure connection using TLS/SSL
  • Optional hourly send rate limit

📥 Reading Emails (EzReader)

  • Connect via IMAP securely using password or OAuth2 token
  • List mailboxes (INBOX, Sent, Drafts, etc.)
  • Filter by: ALL, UNSEEN, FROM, SUBJECT, TEXT, SINCE, BEFORE
  • Retrieve attachments in memory (not saved automatically)
  • Return results as structured EzMail objects

💻 Installation

pip install ezmail

No extra configuration needed — just use your SMTP and IMAP credentials.


🧠 Quick Overview

Class Description
EzSender Composes and sends emails with HTML, inline images, and attachments.
EzReader Reads and filters emails from any IMAP server.
EzMail Represents a single email (sender, subject, body, attachments).

✉️ Example — Sending Emails

from ezmail import EzSender

smtp = {"server": "smtp.gmail.com", "port": 587}
sender = {"email": "me@gmail.com", "password": "app_password"}

ez = EzSender(smtp, sender)
ez.subject = "System Update Report"
ez.add_text("<h2>Hello!</h2><p>The latest system report is attached below.</p>")
ez.add_attachment("report.pdf")

ez.send(["client@example.com", "team@example.com"])

📬 Example — Reading Emails

from ezmail import EzReader

imap = {"server": "imap.gmail.com", "port": 993}
account = {
    "email": "me@gmail.com",
    "auth_value": "oauth2_token_or_password",
    "auth_type": "password"  # or "oauth2"
}

reader = EzReader(imap, account)
reader.connect()

emails = reader.fetch_messages(status="UNSEEN", since="01-Oct-2025")
for mail in emails:
    print(mail.subject, "-", mail.sender)
    if mail.has_attachments():
        for a in mail.attachments:
            print("💎", a["filename"], len(a["data"]), "bytes")

reader.disconnect()

🯩 Advanced Example — Using Templates and Inline Images

ez = EzSender(
    smtp={"server": "smtp.domain.com", "port": 587},
    sender={"email": "me@domain.com", "password": "mypassword"}
)

ez.subject = "Welcome to our platform!"
ez.use_template("templates/welcome.html", name="John", version="3.2.1")
ez.add_image("logo.png", width="150px", cid="logo_img")
ez.send("john@client.com")

🔐 Authentication Methods

Method Description
password Standard login using email and password (supports app-specific passwords).
oauth2 Secure OAuth2 token authentication — required for Gmail and Microsoft accounts.

📦 Dependencies

  • Jinja2 ≥ 3.0.0 (for HTML templates)
  • Built-in modules only: smtplib, imaplib, email, mimetypes, uuid, etc.

🧮 Requirements

  • Python ≥ 3.8
  • Internet access (for SMTP/IMAP servers)

🧳 License

MIT © Luiz Henrique Brunca


🌎 Other Languages

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

py_ezmail-2.0.4.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_ezmail-2.0.4-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file py_ezmail-2.0.4.tar.gz.

File metadata

  • Download URL: py_ezmail-2.0.4.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for py_ezmail-2.0.4.tar.gz
Algorithm Hash digest
SHA256 04eacff901edf879061056d5aeec8e51a7d6c51bec309cf8c874df20cd991d53
MD5 b161b30aa75723beb48d7e811ff05485
BLAKE2b-256 123afea135083933eca76d9a13dde5a459717034fc1d97439dbb471b7bc1922f

See more details on using hashes here.

File details

Details for the file py_ezmail-2.0.4-py3-none-any.whl.

File metadata

  • Download URL: py_ezmail-2.0.4-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for py_ezmail-2.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2e60373e9c9e51ddb6be09e6446b2ba46382508353025eb772e75e7069889b63
MD5 01c4d69f18bf429bf383404b904d0d9c
BLAKE2b-256 b7e5365af085405efe15072fd2ebf65bf36e4031d54a2a602a2ed029655aa11c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page