← back to blog
SYS_LOG :: POST2026_05_0407_MIN#FEATURE

IMAP and SMTP Explained: How AI Reads and Sends Your Email

Understand how IMAP and SMTP work, why they matter for AI email integration, and how tools like Connect My Email use these protocols to give AI assistants real access to your inbox.

If you've ever set up an email client — Outlook, Apple Mail, Thunderbird — you've encountered IMAP and SMTP settings. Most people fill in the server addresses without thinking much about what they mean.

But when it comes to AI email integration, these two protocols are the entire foundation. Understanding how IMAP and SMTP work explains exactly how AI assistants read your inbox, search for messages, and send replies on your behalf — and why the architecture is more secure and straightforward than it might seem.

The Two Protocols Behind Email

Email delivery and retrieval are handled by separate systems. That's not a design quirk — it's intentional, and understanding the split makes everything else clearer.

SMTP: How Email Gets Sent

SMTP (Simple Mail Transfer Protocol) is the protocol used to send email. When you click Send, your email client connects to your provider's SMTP server, authenticates, and hands off the message. The SMTP server then routes the message toward its destination.

SMTP handles outbound mail exclusively. It doesn't know anything about your inbox — it's a delivery mechanism, not a storage system.

Key facts about SMTP:

  • Standard port: 587 (with STARTTLS) or 465 (with SSL)
  • Authentication required: username + password, or OAuth token
  • One-directional: only for sending, never for reading

When an AI assistant sends an email on your behalf — drafting a reply, sending a follow-up, forwarding a message — it's using SMTP to do it.

IMAP: How Email Gets Read

IMAP (Internet Message Access Protocol) is the protocol used to read and manage email stored on a server. Unlike its older counterpart POP3 (which downloads messages and removes them from the server), IMAP keeps messages on the server and syncs changes across devices.

When you open Gmail on your phone and your laptop and both show the same inbox, that's IMAP synchronization at work.

Key facts about IMAP:

  • Standard port: 993 (with SSL)
  • Bidirectional: read messages, search, move, delete, flag
  • Server-side: messages stay on the server; clients see a synchronized view
  • Folder-aware: full access to inbox, sent, drafts, custom folders, and labels

When an AI assistant reads your email — searching for a specific message, retrieving a thread, checking for unread items — it's using IMAP.

How AI Uses IMAP to Read Your Inbox

For an AI assistant to access your inbox, it needs to behave like an email client. That means authenticating with your IMAP server and making standard IMAP commands.

Here's what that looks like step by step:

1. Authentication

The AI tool connects to your IMAP server over an encrypted SSL/TLS connection and authenticates using one of two methods:

App password authentication: You generate a dedicated password in your email provider's security settings. This password works only for the specific integration — it can be revoked without changing your main password. Used by Yahoo, iCloud, Fastmail, and generic IMAP providers.

OAuth 2.0: You authorize the AI tool through your provider's standard login flow. The tool receives an access token (short-lived) and a refresh token (long-lived). Access tokens expire and are automatically refreshed using the refresh token. Used by Gmail and Outlook.

Neither method exposes your main account password to the AI tool.

2. Folder Enumeration

After authenticating, the tool runs IMAP's LIST command to discover your folder and label structure. This tells the AI what's available: INBOX, Sent, Drafts, custom folders, and provider-specific folders like Gmail's All Mail.

IMAP has a built-in SEARCH command that supports filtering by sender, recipient, subject, date range, flags, and keywords. When your AI assistant asks "find emails from my accountant last month," the tool translates that into an IMAP SEARCH command:

SEARCH FROM "accountant@example.com" SINCE 1-Apr-2026 BEFORE 1-May-2026

The server returns a list of message UIDs matching the query — no full message content transferred yet, just identifiers.

4. Message Retrieval

For each message the AI needs to read in full, the tool fetches it using the IMAP FETCH command. A well-built tool fetches only what's necessary:

  • Headers only (for triage and sorting): sender, subject, date, threading headers
  • Plain text body (for reading): skips HTML, images, and attachments
  • Full message (when needed): includes attachments and complete MIME structure

Fetching selectively keeps data transfer small and reduces what's passed to the AI model — important for both performance and privacy.

5. State Management

IMAP is a stateful protocol — the session stays open while the client is connected, and the server pushes updates (new messages, flag changes) in real time. For AI agents that need to react to new email (the "watch inbox" use case), IMAP IDLE is the mechanism: the connection stays open, and the server sends a notification the moment something changes.

How AI Uses SMTP to Send Email

Sending is simpler than reading. When an AI assistant needs to send a message:

  1. The tool opens an SSL connection to your SMTP server
  2. Authenticates with the same credentials used for IMAP
  3. Issues MAIL FROM (sender address), RCPT TO (recipient), and DATA (message content) commands
  4. The SMTP server accepts the message and handles delivery

For replies, proper email threading requires setting the In-Reply-To and References headers to match the original message's Message-ID. A well-built AI email tool handles this automatically so your replies appear in the correct thread.

Provider-Specific Notes

Gmail

Gmail uses OAuth 2.0 and requires the https://mail.google.com/ scope for full IMAP access. Gmail's folder model maps to IMAP using labels — [Gmail]/All Mail contains everything, while user-created labels appear as IMAP folders.

  • IMAP: imap.gmail.com, port 993
  • SMTP: smtp.gmail.com, port 465 or 587

Outlook / Microsoft 365

Microsoft uses OAuth 2.0 via Azure AD. IMAP access must be enabled in the Outlook account settings (it's on by default for personal accounts, but may be disabled in organizational Microsoft 365 environments).

  • IMAP: outlook.office365.com, port 993
  • SMTP: smtp.office365.com, port 587

iCloud Mail

iCloud requires an app-specific password generated at appleid.apple.com. Two-factor authentication must be enabled on the Apple ID.

  • IMAP: imap.mail.me.com, port 993
  • SMTP: smtp.mail.me.com, port 587

Yahoo Mail

Yahoo uses app passwords. Generate one under Account Security in your Yahoo account settings.

  • IMAP: imap.mail.yahoo.com, port 993
  • SMTP: smtp.mail.yahoo.com, port 465

Fastmail

Fastmail supports both app passwords and OAuth. It's one of the cleanest IMAP implementations available.

  • IMAP: imap.fastmail.com, port 993
  • SMTP: smtp.fastmail.com, port 465

What MCP Adds to the IMAP/SMTP Layer

Raw IMAP and SMTP access is necessary but not sufficient for AI email integration. The AI model also needs a structured way to call email operations — a layer that translates natural language intent into protocol commands and returns results the model can reason about.

That's what the Model Context Protocol (MCP) provides.

MCP sits between the AI assistant and the IMAP/SMTP layer. It exposes email operations as named tools (search_emails, get_thread, send_email, etc.), handles session management and authentication, formats results as structured data the LLM can process, and manages errors gracefully.

Without MCP, every AI tool would need to build its own email integration from scratch. With MCP, a single well-built server handles the protocol complexity, and any MCP-compatible AI can use it.

Connect My Email: IMAP + SMTP + MCP, Ready to Go

Connect My Email is an MCP email server that handles all of this — IMAP authentication, search, thread retrieval, SMTP sending, and the MCP tool layer — as a hosted service.

Rather than configuring IMAP credentials, managing OAuth flows, and building MIME parsing into your own tools, you connect your inbox through Connect My Email's dashboard and get a production-ready MCP endpoint that works with your AI assistant and other MCP-compatible AI assistants.

Supported providers: Gmail, Outlook, iCloud, Yahoo, Fastmail, and any generic IMAP server.

Plans

Plan Price Details
Free $0/mo Single inbox, core IMAP/SMTP tools
Pro $9/mo Full feature set, higher limits
Power $25/mo Multiple inboxes, automation-ready
One-Time Sweep $19 Single deep inbox analysis, no subscription

Summary

  • SMTP sends email. IMAP reads, searches, and manages email stored on the server.
  • AI assistants connect via IMAP using app passwords or OAuth — never your main password.
  • IMAP's SEARCH command filters messages server-side; FETCH retrieves content selectively.
  • SMTP handles sending with proper threading headers so replies land in the right thread.
  • MCP provides the structured tool layer that lets AI models call email operations by name.
  • Connect My Email bundles all of this into a ready-to-use MCP server.

Understanding these protocols removes the mystery from AI email integration. It's not magic — it's well-established technology that's been powering email clients for decades, now accessible to AI assistants through a clean protocol layer.

Connect your inbox at connectmyemail.com and give your AI assistant real email access today.

get the next post

Subscribe to the Connect My Email blog.

Notes on AI + email, sent when something's worth reading. No spam.

ready to wire it up?

Connect your real inbox to Claude in 2 minutes.

Get started