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

Uploaded Python 3

File details

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

File metadata

  • Download URL: yiyimail-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 e8085de47046d4ef96f2254e0cb4bab4d87ee74421410aadd4eb008e1bd4486e
MD5 76629e76028ab25f6770597b02781bf4
BLAKE2b-256 b78bbfc9a27a8e9501ab894d6386e98ddc62bd8762e2d9ab55f89eb87a2f7178

See more details on using hashes here.

File details

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

File metadata

  • Download URL: yiyimail-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 69e0607728312be838bcdbb8fd7f3f712877ee970b5639c60c064035e121e556
MD5 f45ab26514e048277920343495945d43
BLAKE2b-256 90fd55905fb63b7a06cef29b9517d3feaff7df9948d17515073631e76fc2c65f

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