Skip to main content

Email Source/Output for Waken — IMAP polling in, SMTP send out.

Project description

waken-email

CI License: MIT

Email Source/Output for Waken — IMAP polling in, SMTP send out.

Like waken-slack/waken-telegram/waken-voice, this is a channel adapter, not an AI backend: it implements Source/Output, not Target. Unlike those siblings, there's no single company or SDK to defer to here — SMTP and IMAP are generic protocols, not a vendor's product, so the configuration and secret names below (IMAP_*/SMTP_*) are this package's own invention, not inherited from anywhere.

Install

pip install waken-email

Usage

from waken import Runtime
from waken_claude import ClaudeAdapter
from waken_email import EmailOutput, EmailSource

runtime = Runtime()
runtime.target("claude", ClaudeAdapter())

runtime.source("email", EmailSource(target="claude"))
runtime.output("email", EmailOutput())

runtime.run()

EmailSource polls an IMAP inbox for new mail and dispatches each new message as an Event, keyed for replies by the sender's address (stashed in Event.metadata["to"]). EmailOutput sends a Target's Response back to that address over SMTP. Registering both under the same name ("email" above) means a reply to the original Target's answer goes back out over the same channel it came in on — see docs/api-spec.md §3 and §9 in the main waken repo for how Runtime.dispatch() resolves delivery.

Configuration

Both classes accept constructor keyword arguments, falling back to environment variables if omitted:

EmailSource Env var Default
host IMAP_HOST required
username IMAP_USERNAME required
password IMAP_PASSWORD required
folder "INBOX"
interval 30.0 seconds
use_ssl True
EmailOutput Env var Default
host SMTP_HOST required
username SMTP_USERNAME required
password SMTP_PASSWORD required
port 587
from_addr username
use_tls True (STARTTLS)

These names are invented for this package specifically — there's no provider SDK whose own default env vars to reuse the way waken-claude reuses ANTHROPIC_API_KEY or waken-slack reuses SLACK_BOT_TOKEN, since SMTP/IMAP are generic protocols implemented by every mail provider, not one company's SDK. See docs/adapter-ci-setup.md in the main waken repo for the broader convention this deliberately doesn't fit.

Design notes and scope boundaries

  • Sync stdlib for IMAP, async library for SMTP. imaplib (stdlib) is wrapped in loop.run_in_executor(...) for EmailSource's polling — the async IMAP libraries that exist (e.g. aioimaplib) are far less mature/widely used than stdlib imaplib, the same reasoning waken-bedrock applies to wrapping synchronous boto3. EmailOutput, by contrast, uses aiosmtplib directly rather than wrapping stdlib smtplib — a mature, widely-used async SMTP client actually exists for this side of the protocol, so there's no reason to prefer the executor-wrapping workaround here.
  • IMAP UID tracking, not an in-memory "seen" set. EmailSource tracks the highest IMAP UID processed so far rather than keeping an in-memory set of seen message ids — UIDs are monotonically increasing per mailbox (RFC 3501), so this is the IMAP-native equivalent of the built-in FilesystemSource's _seen set or waken-telegram's offset. A fresh IMAP connection is opened per poll and closed at the end of it, rather than holding one connection open across polls — simpler and more robust against idle-timeout disconnects. Whatever is already in the mailbox when start() runs is the baseline, not a new arrival, and never fires — the same rule FilesystemSource applies to pre-existing files.
  • Plain text only. Message bodies are parsed with stdlib email (get_body(preferencelist=("plain",))) and only the first text/plain part is used. An HTML-only email with no plain-text alternative part comes through with an empty body. Parsing or stripping HTML, and sending HTML replies, are both out of scope for v1. response.files attachments are likewise not sent by EmailOutput yet.

Development

git clone https://github.com/WakenHQ/waken-email
cd waken-email
pip install -e ".[dev]"
pytest

License

MIT

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

waken_email-0.1.0.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.

waken_email-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: waken_email-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for waken_email-0.1.0.tar.gz
Algorithm Hash digest
SHA256 94e1a163513ecb61b535c96df1a3456f4028c936846409e43e179291f99f96b9
MD5 be52ee5324cfe7876bc234772d3769ff
BLAKE2b-256 c50a17b2c45d83d53e5d7db63b5859a234b1ddd5ad434a73dee24adb640a3b29

See more details on using hashes here.

Provenance

The following attestation bundles were made for waken_email-0.1.0.tar.gz:

Publisher: publish.yml on WakenHQ/waken-email

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: waken_email-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for waken_email-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75cc6c4a2e7f70c51289419d697e917f2c4239fad7efb82a9898ab5a07341aa6
MD5 ec1778bc768d68b2dd90e038edef00f9
BLAKE2b-256 a8f44ef0225081062243aea8f1b5a19a85fd00be261bcf08ca4a43e96839eb6e

See more details on using hashes here.

Provenance

The following attestation bundles were made for waken_email-0.1.0-py3-none-any.whl:

Publisher: publish.yml on WakenHQ/waken-email

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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