Class EmailChannel

java.lang.Object
com.tnsai.channels.email.EmailChannel
All Implemented Interfaces:
ChannelAdapter

@Channel(id="email", displayName="Email") public class EmailChannel extends Object implements ChannelAdapter
Email channel adapter (IMAP poll + SMTP send) for TnsAI agents.

Inbound: polls a configured IMAP folder on a fixed schedule, converts each UNSEEN message that passes the senderAllowlist into a UnifiedMessage, and delivers it via ChannelContext.onMessage(com.tnsai.channels.api.UnifiedMessage). Read messages are marked SEEN so the next poll cycle skips them.

Outbound: each UnifiedResponse becomes an SMTP send addressed to the original sender of the thread. Thread continuity is preserved by setting In-Reply-To to the last seen Message-ID and a subject derived from the inbound subject (prefixed with Re: if not already there). Recipient + Message-ID state is held per-conversationId in a ConcurrentHashMap for the channel's lifetime — restart loses this state, which is acceptable for an async channel where threads may span days.

Configuration comes from EmailChannelConfig; in production a consumer reads it from its configuration and passes it through the factory. When started without explicit config the channel attempts EmailChannelConfig.fromEnvironment() and reports a fatal ChannelError if required vars are missing.

Thread safety: send(com.tnsai.channels.api.UnifiedResponse) can be invoked from any agent thread; the IMAP poll runs on a single-threaded ScheduledExecutorService. SMTP Transports are short-lived per-send; IMAP Stores are opened per poll. Neither is held across the whole channel lifetime, so there's no shared mutable JavaMail state to guard.