I’m excited to announce the release of MailToolsBox 1.1.0, a major update to my open‑source Python email library. This update turns MailToolsBox into a full‑stack email toolkit: secure SMTP sending (sync and async), Jinja2 templates, bulk sending, and now an upgraded IMAP client for receiving, searching, and managing mailboxes.
Whether you need to send transactional emails, build an async service, or automate mailbox ingestion, this version covers the full lifecycle.
🚀 What’s New in 1.1.0
1. SMTP Revamp
- Security Modes: choose between
auto
,ssl
,starttls
, ornone
. - OAuth2 XOAUTH2 Support: works with Gmail, Office365, and other modern providers.
- Presets: one‑line configuration for Gmail (app passwords) and Exchange Online.
- Reply‑To Support: configure a reply address different from the sender.
- Smart Attachments: MIME‑aware handling, with correct headers for text, PDF, images, etc.
- Plain‑text fallback for HTML emails: improves deliverability across clients.
- Async & Bulk Sending: efficient, non‑blocking sends for high‑volume systems.
2. IMAP Client Upgrade
- Security Modes:
auto
,ssl
,starttls
,none
. - OAuth2 XOAUTH2 Support for Gmail/Exchange Online.
- Search & Fetch: powerful queries (
UNSEEN
,SINCE
,FROM
, etc.). - Message Parsing: decode headers, text, HTML, attachments with correct charset handling.
- Mailbox Management: list, move, delete, expunge, mark seen/flagged.
- Exports:
- Save as
.eml
- Save attachments
- Dump JSON or text
- Save as
- Context Manager Support:
with ImapClient.from_env() as imap: ...
3. Developer Experience
- Environment Variable Config for both SMTP and IMAP.
- Backward Compatibility Layer via
SendAgent
(deprecated but available). - Improved Logging for easier debugging.
- Comprehensive README with recipes for Gmail, Exchange, and custom relays.
🔧 Installation
Install from PyPI:
pip install MailToolsBox
📤 SMTP Usage Examples
Send a simple email
from MailToolsBox import EmailSender
sender = EmailSender.for_gmail_app_password("you@gmail.com", "abcd abcd abcd abcd")
sender.send(["to@example.com"], "Hello", "Plain text body")
Send HTML + attachments
html = "<h1>Report</h1><p>See attachment.</p>"
sender.send(
recipients=["to@example.com"],
subject="Monthly Report",
message_body=html,
html=True,
attachments=["report.pdf", "chart.png"]
)
Use a Jinja2 template
sender.send_template(
recipient="to@example.com",
subject="Welcome",
template_name="welcome.html",
context={"user": "Alex", "link": "https://example.com/activate"}
)
Async sending
import asyncio
async def main():
await sender.send_async(
["to@example.com"], "Async Email", "Sent without blocking!"
)
asyncio.run(main())
📥 IMAP Usage Examples
Connect and fetch unseen emails
from MailToolsBox import ImapClient
with ImapClient.from_env() as imap:
imap.select("INBOX")
uids = imap.search("UNSEEN")
for uid in uids:
msg = imap.fetch(uid)
print(msg.subject, msg.from_[0].email if msg.from_ else None)
Save attachments
attachments = imap.save_attachments(msg, "./attachments")
Export mailbox as JSON
imap.download_mail_json(lookup="UNSEEN", save=True, path="./dumps")
Save emails as .eml files
imap.download_mail_eml(directory="./eml", lookup="ALL")
🔒 Security Best Practices
- Use app passwords (Gmail, Exchange) instead of raw credentials.
- Prefer OAuth2 tokens for long‑running services.
- Always use
ssl
(port 465) orstarttls
(port 587 / 993). - Only use
none
inside trusted networks.
📈 Why this matters
Most Python email libraries are either outdated (no async, no OAuth2), or too limited (send only). MailToolsBox now provides a full end‑to‑end solution: send, manage, and automate email workflows with modern security.
This makes it a great fit for:
- SaaS applications that need transactional email.
- Internal bots for notifications or reports.
- Automated mailbox processors (support tickets, monitoring alerts).
- Personal productivity scripts.
📦 Next Steps
Future versions will focus on:
- Retry logic and connection pooling for high‑volume sending.
- Typed exceptions (e.g.
MailAuthError
,MailTempError
). - DKIM signing support.
- IMAP IDLE and Gmail‑specific extensions.
📜 Conclusion
MailToolsBox 1.1.0 is more than an update—it’s a transformation into a modern email framework for Python. It bridges the gap between sending and receiving with security, async support, and developer‑friendly features.