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.2.tar.gz (14.2 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.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ezmail-2.0.2.tar.gz
  • Upload date:
  • Size: 14.2 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.2.tar.gz
Algorithm Hash digest
SHA256 8088bd341724b6fea3015ec88513cb272bd7d06cc0f844a28928ed45d193407b
MD5 9b8a23a02720607da3a75fd37b73649c
BLAKE2b-256 2ab38f06aed27158b710c2042b5eec699dc97de0920ce9fe54e22ce904bf9879

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ezmail-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17313007a8e9bf52583effcc57467ec8b1445519f354c1e80fa48326e0c179fc
MD5 e2ac53363519aca188b7b6f0ea276a49
BLAKE2b-256 55d54c850769415d92ff6e7932c3c60c3363657896f4fd45517ef39d641fb216

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