Skip to main content

A high-performance, modern Python library for email processing (IMAP/POP3/SMTP).

Project description

YIYIMail Logo

YIYIMail 🚀

中文说明 | English Version

YIYIMail is a high-performance, modern Python library for email processing. It is designed to replace legacy libraries by providing seamless support for IMAP, POP3, and SMTP, featuring high-performance server-side search, elegant HTML/CID parsing, and extreme ease of use.

🌟 Key Features

  • Modern Protocol Support: Full support for IMAP, POP3, and SMTP. Auto-identification for personal (Gmail, Outlook, 163, QQ) and Enterprise providers (Tencent, Ali, Netease).
  • High-Performance Search: Leverage IMAP server-side search to locate emails instantly. Filter by Subject, Sender, Date, and Unseen status with limit support.
  • Superior Compatibility: Built-in IMAP ID command support to pass security checks of providers like 163.com and Tencent.
  • Smart Folder Matching: Automatically handles Modified UTF-7 encoding for non-ASCII folder names. Supports direct use of localized names like "已发送" or "Sent Messages".
  • Elegant Parser: Automatically handles CID inline images and generates Base64-rendered HTML for perfect offline viewing.
  • Utility Toolbox: Built-in show() for pretty printing and save()/load() for local persistence.
  • Type Safe: Fully typed with Python 3.7+ type hints.

📦 Installation

pip install YIYIMail

🚀 Quick Start

1. Connection

YIYIMail automatically identifies server settings based on your email domain.

import YIYIMail

# Use authorization codes for services like 163, QQ, etc.
mail = YIYIMail.connect('your_name@163.com', 'your_auth_code')

# Enterprise mail support (Auto-detects Tencent, Ali, Netease)
# mail = YIYIMail.connect('admin@exmail.qq.com', 'password')

# Or manual server configuration
# mail = YIYIMail.connect('user@company.com', 'pwd', smtp_host='smtp.company.com', imap_host='imap.company.com')

2. Send Emails

Supports multiple recipients, attachments, and HTML content.

mail.send(
    recipients=['friend@example.com'],
    subject='Hello',
    content='This is a test email',
    html='<h1>Hello</h1><p>Sent via YIYIMail!</p>',
    attachments=['/path/to/report.pdf']
)

3. Advanced Search (IMAP)

Search on the server without downloading everything.

# Search for emails after May 1st, 2026, limit to 5 latest results
results = mail.search(after='2026-05-01', subject='Report', limit=5)

# Search for unseen emails from a specific sender
unread = mail.search(sender='boss@company.com', unseen=True)

# Search in a specific folder
sent = mail.search(subject='Project', folder='Sent Messages')

4. Fetch & Display

# Get the latest email
latest = mail.fetch_latest()

# Get a range of emails
mails = mail.fetch_mails(start=1, end=10)

# Pretty print content to console
YIYIMail.show(latest)

5. Status Management

uid = latest['uid']
mail.mark_as_read(uid)    # Mark as seen
mail.mark_as_unread(uid)  # Mark as unseen

6. Persistence

# Save to local JSON
YIYIMail.save(latest, 'my_mail.json')

# Load from local
local_mail = YIYIMail.load('my_mail.json')

7. Mailbox Information

# Get mailbox statistics (total count, size)
stats = mail.info()
print(f"Total Mails: {stats['count']}, Size: {stats['size_bytes']} bytes")

🛠️ Folder Management

Use mail.folders() to get decoded folder names from the server.

print(mail.folders()) 
# Output: ['INBOX', 'Drafts', 'Sent Messages', 'Trash', ...]

⚖️ License

MIT License

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

yiyimail-1.0.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yiyimail-1.0.2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file yiyimail-1.0.2.tar.gz.

File metadata

  • Download URL: yiyimail-1.0.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for yiyimail-1.0.2.tar.gz
Algorithm Hash digest
SHA256 93e39b977d72c24eaf3ae833d3356b60ba6d34879c11f37e5d1f73c49430ef64
MD5 301dc4da31ac5406d2d20a47fab37fa9
BLAKE2b-256 e6a077ba40d1ebc51e297ee8bb836df5d7eef1e357934ed7bfe7c38e2fd90509

See more details on using hashes here.

File details

Details for the file yiyimail-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: yiyimail-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for yiyimail-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3b7e7ddfbf7bcb15648bc9fc25dfcb427bbd3102228766bd1e7149072f527e8
MD5 77d5f3f3d0516b324c7989da7e066d01
BLAKE2b-256 1d62d13d546c1583b04fb0e728ca9cf1e0ca3a65c3a5600d4b26b379f78a126c

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