IMAP & MAIL
Connect to any IMAP mailbox and send via SMTP. Read, search, fetch, and send email server-side. One session per namespace — connect once, use across the query.
| Verb | Description |
|---|---|
IMAP "host" WITH "pass" AS "user" | Connect and authenticate. Stores session for the namespace. |
MAIL INBOX SET ?emails | Last 20 emails from INBOX — array of {uid,subject,from,to,date,body} |
MAIL UNREAD SET ?emails | All unread (UNSEEN) emails |
MAIL SEARCH "criteria" SET ?emails | IMAP search: FROM "addr", SUBJECT "text", SINCE "01-Jan-2026", UNSEEN |
MAIL "uid" SET ?msg | Fetch single email by UID |
MAIL SEND TO "addr" WITH "subject" AS "body" | Send via SMTP |
MAIL CLOSE | Clear stored credentials |
Connect (Gmail requires an App Password)
IMAP "imap.gmail.com" WITH "app_password" AS "user@gmail.com" SET ?ok
AFTER EMIT ?ok
Read inbox
IMAP "imap.gmail.com" WITH "app_password" AS "user@gmail.com" SET ?ok
AFTER MAIL INBOX SET ?emails
AFTER EMIT ?emails(0)(subject)
Unread only
IMAP "imap.gmail.com" WITH "app_password" AS "user@gmail.com" SET ?ok
AFTER MAIL UNREAD SET ?new
AFTER LENGTH ?new SET ?n
AFTER EMIT ?n & " unread"
Search
IMAP "imap.gmail.com" WITH "app_password" AS "user@gmail.com" SET ?ok
AFTER MAIL SEARCH "FROM boss@company.com" SET ?msgs
AFTER EMIT ?msgs
Send
IMAP "imap.gmail.com" WITH "app_password" AS "user@gmail.com" SET ?ok
AFTER MAIL SEND TO "recipient@example.com" WITH "Hello!" AS "This is the body"
AFTER MAIL CLOSE