Installation
Install the Mail interface dependencies:Setup
Configuration via constructor parameters or environment variables:The interface uses a pull-based model - you trigger email checks via the
/mail/check endpoint (or use heartbeat auto-poll), and the agent processes unread emails.Common Provider Settings
Operating Modes
- TASK (default) — Each email is processed as an independent task; no conversation history. The agent decides to reply or ignore. Best for classification, auto-responders, one-off processing.
- CHAT — Emails from the same sender share a conversation session. The agent remembers context from previous emails. Best for support threads and ongoing conversations.
Reset Command (CHAT mode only)
In CHAT mode, senders can clear their conversation by sending an email with the reset command in the body (e.g./reset). Configure it with reset_command; set to None to disable.
If the agent has a workspace configured, the reset command will also trigger a dynamic greeting message based on the workspace configuration. See Workspace for details.
Heartbeat (Auto-Poll)
When used with anAutonomousAgent that has heartbeat=True, the interface automatically polls the IMAP mailbox for new emails on a configurable interval. No need to manually trigger /mail/check.
Access Control (Whitelist)
Passallowed_emails (list of email addresses). Only emails from those senders are processed; others are silently skipped and marked as read. Omit allowed_emails (or set None) to allow all senders.
Attachments
The Mail interface fully supports attachments in both directions:- Incoming: Attachments on received emails are downloaded to temporary files and passed to the agent via
Task(context=...). Temp files are cleaned up automatically after processing. - Outgoing: The agent can send emails with file attachments using the
send_email_with_attachmentsandsend_reply_with_attachmentstools.
Multiple Recipients
Thesend_email tool supports sending to multiple recipients with CC and BCC:
Event Deduplication
The interface automatically prevents processing the same email twice within a 5-minute window. This protects against rapid consecutive calls to/mail/check.
Example Usage
Create an agent, expose it with theMailInterface, and serve via InterfaceManager. Example with TASK mode, API secret, and whitelist:
CHAT Mode Example
/reset in an email body to start fresh.
Core Components
-
MailInterface(interface): Wraps an UpsonicAgentfor SMTP/IMAP email via FastAPI. -
MailTools(toolkit): Provides 17 agent-facing tools for email operations (send, receive, search, flag, delete, move, attachments). -
InterfaceManager.serve: Serves the FastAPI app using Uvicorn.
MailInterface Interface
Main entry point for Upsonic Mail applications.
Initialization Parameters
Key Methods
Endpoints
Mounted under the/mail prefix. All endpoints require the X-Upsonic-Mail-Secret header if api_secret is configured.
POST /mail/check
- Triggers a check for unread emails and processes them through the agent.
-
Query parameter:
count(default: 10) - maximum number of emails to process. - In TASK mode: agent decides to reply or ignore each email.
- In CHAT mode: emails are routed to per-sender conversation sessions.
-
Returns:
200 CheckEmailsResponsewithstatus,processed_count, andemail_uids.
GET /mail/inbox
- Lists the most recent emails (read and unread).
-
Query parameters:
count(default: 20, max: 100),mailbox(default: INBOX). -
Returns:
200 EmailListResponsewithcountandemailsarray.
GET /mail/unread
- Lists unread emails only.
-
Query parameters:
count(default: 20, max: 100),mailbox(default: INBOX). -
Returns:
200 EmailListResponsewithcountandemailsarray.
POST /mail/send
- Sends a new email.
-
Request body:
to(string or array),subject,body,cc(optional),bcc(optional),html(optional boolean). - Supports single and multiple recipients.
-
Returns:
200 {"status": "success", "message": "..."}.
POST /mail/search
- Searches emails using IMAP search criteria.
-
Request body:
query(IMAP search string),count(default: 10),mailbox(default: INBOX). -
Returns:
200 EmailListResponsewith matching emails.
GET /mail/folders
- Lists all available mailboxes/folders on the IMAP server.
-
Returns:
200 {"status": "success", "folders": [...]}.
GET /mail/status
- Gets the status of a mailbox (total, unseen, recent message counts).
-
Query parameter:
mailbox(default: INBOX). -
Returns:
200 MailboxStatusResponsewithmailbox,total,unseen,recent.
POST /mail/{uid}/read
- Marks an email as read by its UID.
-
Query parameter:
mailbox(default: INBOX). -
Returns:
200 {"status": "success", "uid": "...", "action": "marked_read"}.
POST /mail/{uid}/unread
- Marks an email as unread by its UID.
-
Returns:
200 {"status": "success", "uid": "...", "action": "marked_unread"}.
POST /mail/{uid}/delete
- Deletes an email by its UID.
-
Returns:
200 {"status": "success", "uid": "...", "action": "deleted"}.
POST /mail/{uid}/move
- Moves an email to a different mailbox/folder.
-
Query parameter:
destination(required),source(default: INBOX). -
Returns:
200 {"status": "success", "uid": "...", "action": "moved", "destination": "..."}.
GET /mail/health
- Health/status of the interface including IMAP connectivity check.

