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.6.tar.gz (14.5 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.6-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_ezmail-2.0.6.tar.gz
  • Upload date:
  • Size: 14.5 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.6.tar.gz
Algorithm Hash digest
SHA256 2aca87bca8caeb108f1ace5e7e6aaaf365339268af4be49717c3c899fab89537
MD5 954c87eb9fbcee4dd7256fe002324168
BLAKE2b-256 56f59823659a5018814aaf1d9b6025894be4481698b07c24b1da649fef9ae63c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_ezmail-2.0.6-py3-none-any.whl
  • Upload date:
  • Size: 12.6 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 6b5af010143087e15a874e4032e3a9926a8f243b685a2b62fc30b049184945ec
MD5 5766b02052a2e8c2c4b334234513e0f1
BLAKE2b-256 234756c6421012209e16317232657831be9ebd1e163f3a3646ece1aeab30b32d

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