MailToolsBox – Python Email Library

A modern Python email toolkit with SMTP, IMAP, OAuth2, Jinja2 templates, and async support. Secure, reliable, and production-ready.

MailToolsBox – Python Email Library

Project metadata

Tech stack
Python, AsyncIO, SMTP, IMAP, Jinja2, OAuth2
Status
released
Published
August 30, 2023
Updated
November 22, 2025

Project details

MailToolsBox

A modern, production-grade email toolkit for Python. Clean SMTP sending, a full IMAP client, strong security defaults, async APIs, templates, and optional validation — all in one compact package.

Python Library Platforms: Linux, macOS, Windows Status: Live on PyPI

Overview

MailToolsBox is a pragmatic email toolkit built for real-world Python automation. It combines reliable SMTP sending and a capable IMAP client under a unified, clean API. The library is designed around explicit security choices, predictable defaults, and extensibility.

Whether you are sending one message, generating templated notifications, reading mailbox contents, or exporting entire folders, MailToolsBox provides a consistent, well-tested interface backed by stable protocols and optional modern features such as OAuth2 XOAUTH2 authentication.

Core Features

SMTP sending (sync & async)

Send emails with a simple API, including:

  • Plain text and HTML modes
  • Attachments, CC/BCC, Reply-To
  • Bulk and per-recipient sending
  • Async sending via aiosmtplib
  • XOAUTH2 authentication support

IMAP client with full mailbox control

Robust IMAP operations for automation:

  • List and select mailboxes
  • Search (UID-based), fetch, and fetch_many
  • Parse headers, flags, plain text, HTML, attachments
  • Mark seen, add/remove flags
  • Move, delete, expunge
  • Export tools: save attachments, dump JSON, save .eml

Security modes with explicit control

  • auto — picks the safest option based on port and server capabilities
  • starttls — explicit STARTTLS upgrade
  • ssl — implicit SSL, typical for port 465
  • none — plain mode for trusted internal networks
  • allow_invalid_certs — for LAN/self-signed certificates

Templates and plain text fallback

Jinja2 templating with auto-escape ensures clean rendering. HTML emails automatically include a plain-text alternative for improved deliverability.

Environment variable configuration

Both EmailSender and ImapClient support zero-code configuration:

  • EmailSender.from_env()
  • ImapClient.from_env()

Ideal for Docker, CI/CD, and serverless environments.

Backward compatibility

Legacy SendAgent and ImapAgent remain available for older codebases while transitioning to the modern API.

Next step

Use the available project links or continue into related Rambod Dev learning content.

What To Do Next

Continue from this project into practical learning and follow-up content.

Share this page

Send it to your network in one tap.

Instagram doesn’t provide direct web share links. We copy your URL and open Instagram.