@cool-ai/beach-channel-email
v0.3.1
Published
Email edge for Beach applications — IMAP inbound and SMTP outbound, gated by Delivery Manifests.
Readme
@cool-ai/beach-channel-email
The email channel adaptor: IMAP polling inbound, SMTP outbound. It implements core's ChannelAdaptor, so the channel-router routes its inbound messages and delivers its replies like any other channel. The IMAP and SMTP wire layers live here too — this package folds in what used to be @cool-ai/beach-transport-email.
Home: cool-ai.org · Documentation: cool-ai.org/docs
Install
pnpm add @cool-ai/beach-channel-email imapflow mailparser nodemailerimapflow, mailparser, and nodemailer are peer dependencies, so you control their versions and can share them with the rest of your application.
Use
import { EmailChannelAdaptor } from '@cool-ai/beach-channel-email';
import { renderToStaticHTML, renderToStaticText } from '@cool-ai/beach-a2ui-renderer-static';
const email = new EmailChannelAdaptor({
imap: { host: 'imap.example.com', port: 993, secure: true, auth: { type: 'password', user, pass } },
smtp: { host: 'smtp.example.com', port: 587, secure: false, auth: { type: 'password', user, pass }, from: user },
uidState, // you persist the last-seen UID
inbound: (req) => channelRouter.inbound(req),
render: (parts) => ({ html: renderToStaticHTML(parts), text: renderToStaticText(parts) }),
});
await email.start(); // begin polling (or mode: 'idle' for IMAP IDLE)
// Register `email` as a channel-router adaptor so replies are sent by SMTP.- Inbound. Each parsed email becomes an
InboundRequest: the body is handed through channel-blind, the thread is taken off the References chain, and a reply destination carries the recipient and threading headers. NoMissiveis built — that interpretation is the consumer's. - Outbound. The consumer-wired
renderturns the reply's parts into the email body; the adaptor reads the threading metadata off the destination, assembles the message, and sends it by SMTP. Wire in a@cool-ai/beach-channel-composerif you want a model to write the prose.
OAuth2 (XOAUTH2) is supported on both IMAP and SMTP via a tokenProvider; Beach calls it per connection and never caches tokens.
