Skip to main content

Async IMAP client for streaming email messages

Project description

Mailstream

Overview

MailStream is an asynchronous IMAP email client built with aioimaplib. It supports streaming emails, polling for updates, and broadcasting new emails to listeners.

Features

  • Asynchronous IMAP connection
  • Fetch unseen emails
  • Broadcast new emails to subscribers
  • Easily integrate with context management

Installation

pip install mailstream

Quick Start

import asyncio
from mailstream import MailStreamClient, Config

async def process_email(mail):
    print(f"New email from: {mail.from_email}")
    print(f"Subject: {mail.subject}")

config = Config(
    host="imap.example.com",
    port=993,
    email="your_email@example.com",
    password="your_password"
)

async def main():
    client = MailStreamClient(config)
    await client.connect()

    # Subscribe to new emails
    listener = client.subscribe()
    
    # Process emails from listener
    while True:
        mail = await listener.get()
        await process_email(mail)

    # Close connection
    await client.close()

asyncio.run(main())

Configuration Options

  • host: IMAP server hostname (required)
  • email: Login email (required)
  • password: Login password (required)
  • port: IMAP server port (default: 993)
  • mailbox: Target mailbox (default: 'INBOX')

Advanced Usage

Fetching Unseen Mails

# Retrieve all unseen emails
unseen_mails = client.get_unseen_mails()
for mail in unseen_mails:
    print(mail.subject)

Multiple Listeners

async def listener1(mail):
    print("Listener 1 received:", mail.subject)

async def listener2(mail):
    print("Listener 2 received:", mail.subject)

listener1_queue = client.subscribe()
listener2_queue = client.subscribe()

Waiting for New Emails

await client.wait_for_updates(poll_interval=10.0)

Error Handling

from mailstream import ConnectionError, AuthenticationError

try:
    client = MailStreamClient(
        host='imap.example.com',
        email='your_email@example.com',
        password='your_password'
    )
    await client.connect()
except (ConnectionError, AuthenticationError) as e:
    print(f"Connection failed: {e}")

Contributing

Contributions are welcome! Please see our contributing guidelines for more details.

License

MIT

Support

For issues, please open a GitHub issue in the repository.

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

mailstream-0.1.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

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

mailstream-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file mailstream-0.1.0.tar.gz.

File metadata

  • Download URL: mailstream-0.1.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for mailstream-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ab16d9d209c384960b1b6a3f093cb1b9e78696cd9f5979b972330a7a1f47474
MD5 b4d92707cdf822209c32c5b3c10ff303
BLAKE2b-256 9cf844dcf95e68ba99d684355fb8b05e5ac8034d92f832c7dd2848b8e9c276b0

See more details on using hashes here.

File details

Details for the file mailstream-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mailstream-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.5

File hashes

Hashes for mailstream-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38377aeb6337033dd87662a2b0124c7622670fd46257e81d15f1faf321e02afe
MD5 a771b24005d32880951059448a92fe63
BLAKE2b-256 df8840af1d0f3cdc58b1a72597cf5ae2e63ed39cf51a58a84dc1560a6514f585

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