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.3.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.3-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ezmail-2.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 7fb9913b2882a1865d30f0505c2670a1d520202ff4e87f829643be142a8a5dab
MD5 d84db786e0a31d2d72911ea63ea4edb3
BLAKE2b-256 1f6763acf1349a2bc671d0bfe7ef2faa52f1b5fa91b8a21fee910b528398d544

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ezmail-2.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d9d13aa05f05505c3ed34010e8fc9ca920922030335764d22925a1624c79759
MD5 d74e3b8e7e9278c43c42861d5ac40a0f
BLAKE2b-256 798e6537a89d1a43180b0cffe67699cc7e11104a5e465e9a289b1c0857fd5812

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