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.5.tar.gz (14.4 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.5-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ezmail-2.0.5.tar.gz
  • Upload date:
  • Size: 14.4 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.5.tar.gz
Algorithm Hash digest
SHA256 0d939aeaa2f23d11baa6b36e4a708e06c489575bd39363d39a1c946db5b3ac5a
MD5 bf4de77bb2aa3058e056ca9b01c59269
BLAKE2b-256 a6ba27adb92d302d36b5d554447dbf52cd815429961ea043ea6dfd348dfbb400

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ezmail-2.0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.5 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6a3e68ca740435c1b9d53cb591308c6e1ce0b3cc69f798c49d87de04d087da86
MD5 bbddcfe06a0ce3883a244481c91ccd55
BLAKE2b-256 4d20aca519a4bf293b069e5174aee4d827bcc936b206a9b699f85387684db555

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