Launch-Free 3 months Builder plan-
Pixel art lobster mascot illustration for email infrastructure — autogen email integration

AutoGen email integration: 3 methods compared

Three ways to give your AutoGen agents email. Code examples, security tradeoffs, and what to watch for in production.

8 min read
Ian Bussières
Ian BussièresCTO & Co-founder

AutoGen makes it straightforward to build multi-agent teams that call tools and coordinate on complex tasks. But the moment one of those agents needs to send or read email, you're dealing with SMTP configuration and OAuth token management. Neither was designed for programmatic access by autonomous agents.

I've tested the three main approaches to AutoGen email integration over the past few months. Here's how each one works, where it falls short, and what to consider before shipping one to production.

How to integrate email with AutoGen (3 methods)#

  1. Composio + AutoGen: OAuth-based integration with managed credential exchange and broad provider support.
  2. autogen-ext-email: Direct SMTP/IMAP connection using raw credentials, lightweight and self-hosted.
  3. MCP email server: Protocol-native, with dynamically discovered tools loaded through a single endpoint.

Composio is the fastest path for prototyping with OAuth-protected providers like Gmail. The autogen-ext-email package gives you direct control over mail server connections. MCP fits agents that already use the Model Context Protocol for other capabilities and want email to work the same way.

Composio: the OAuth route#

Composio sits between AutoGen and email providers, handling OAuth token exchange so your agent never touches raw passwords. You authenticate once through their dashboard, and the agent gets callable actions like GMAIL_SEND_EMAIL or GMAIL_FETCH_EMAILS.

from composio_autogen import ComposioToolSet, Action

toolset = ComposioToolSet()
tools = toolset.get_tools(actions=[Action.GMAIL_SEND_EMAIL])

assistant = AssistantAgent(
    name="email_agent",
    llm_config=llm_config,
    tools=tools
)

This also works with Outlook. Composio supports both providers through the same interface, which is handy if your agents interact with corporate Microsoft 365 inboxes alongside personal Gmail accounts. You can also wire up event triggers: Composio supports gmail_new_gmail_message events that fire your AutoGen workflow when a new email arrives, so you don't need to poll.

The tradeoff: every email operation routes through Composio's servers. Your agent's ability to send and receive depends on their uptime and pricing. For a weekend prototype, that dependency is invisible. For a production agent processing hundreds of messages daily, it's a single point of failure you don't own.

There's also a design mismatch worth thinking about. Composio was designed for humans who want agents to handle tasks on existing accounts. An agent that needs its own independent mailbox is solving a different problem entirely.

Raw SMTP with autogen-ext-email#

The autogen-ext-email package takes the opposite approach: your agent gets direct SMTP and IMAP credentials, no intermediary.

from autogen_ext_email import EmailAgent, EmailConfig

agent = EmailAgent(
    name="email_agent",
    model_client=model_client,
    email_config=EmailConfig(
        email="agent@yourdomain.com",
        password="your-app-password",
        server="smtp.gmail.com",
        port=587
    )
)

This is the most transparent method. You see exactly what's happening, there's no third-party service in the path, and setup takes about ten minutes if you already have SMTP credentials ready. Your agent can read incoming emails and send replies within the same execution loop.

The problem is sitting right there in the code sample. A plaintext password in the source file. Every example in the package's GitHub repo does the same thing. In production, you'd pull credentials from environment variables (os.environ["EMAIL_PASSWORD"]) or a secrets manager, but the library doesn't push you in that direction or even mention it in the README.

Gmail's app passwords make this worse. Google only issues them for accounts with two-factor authentication enabled, and each app password grants full account access. Not scoped to sending. Not read-only. Full access to the inbox, sent folder, contacts, and drafts. If that credential leaks, the attacker owns the entire mailbox.

Rate limits are the other issue. Gmail caps consumer accounts at roughly 500 sends per day (2,000 for Google Workspace). The autogen-ext-email package doesn't include retry logic or rate-limit detection. Your agent hits a 550 rejection with no graceful fallback unless you build that handling yourself.

Warning

The autogen-ext-email package was built against AutoGen 0.4.9. If you're still on AutoGen 0.2, you'll need to restructure your agent code. The 0.2 ConversableAgent pattern is incompatible with the newer AssistantAgent approach.

The MCP approach#

Model Context Protocol flips the integration model. Instead of installing an email-specific package, you run an MCP server that exposes email operations as discoverable tools. AutoGen 0.4 added native MCP support, making this approach feel more natural than it would have a year ago.

from autogen_ext.tools.mcp import McpWorkbench

email_tools = McpWorkbench(server_url="http://localhost:3001")
agent = AssistantAgent(
    name="email_agent",
    tools=await email_tools.list_tools()
)

Your agent connects to the MCP server, discovers available actions (send, receive, search, label), and calls them like any other tool function. Swap the email backend for a different provider, and the agent code stays the same.

The flexibility is real, but so is the immaturity. Most email MCP servers on GitHub are weekend proof-of-concept projects with minimal error handling. You're responsible for hosting the server and managing reconnections when things break. The ecosystem doesn't have a dominant, well-maintained email implementation yet, so you'll likely end up forking someone's repo and patching it yourself.

One thing MCP does well: it's the cleanest path for agents that already use MCP for file access, web browsing, or database queries. Adding email becomes another tool endpoint, not a separate SDK with its own authentication story. If AutoGen's MCP support matures alongside better email MCP servers, this could become the default approach within a year.

Where all three methods fall short#

Every method above assumes a human already created the email account, configured the credentials, and handed them to the agent. For one agent, that's trivial. For ten agents that each need their own address, you're manually provisioning Gmail accounts or buying Workspace seats at $7/month each.

None of these integrations handle inbox provisioning. They connect to existing mailboxes. They don't create new ones.

Deliverability is another shared blind spot. None of the three manage sender reputation or handle bounce processing. An AutoGen agent that starts sending from a fresh domain will land in spam folders consistently. We covered the common setup mistakes that tank deliverability in a previous post, and they apply to every method here.

Security is uneven across all three. Composio abstracts credentials but introduces a trust boundary with a third party. The autogen-ext-email package exposes secrets by default. MCP servers range from careful to careless depending on the author. None of them scan incoming emails for prompt injection, which matters when your agent is autonomously reading and acting on messages from unknown senders.

An agent-first alternative#

There's a different approach: instead of connecting AutoGen agents to human email accounts, give them access to email infrastructure designed for agents from the ground up.

LobsterMail works this way. Your agent provisions its own inbox through an API call, no human signup required. The SDK handles authentication, inbox creation, sending, and receiving. Incoming messages get scored for prompt injection before the agent processes them, which directly addresses the security gap in the three methods above.

import { LobsterMail } from '@lobsterkit/lobstermail';

const lm = await LobsterMail.create();
const inbox = await lm.createSmartInbox({ name: 'My AutoGen Agent' });
// inbox.address → my-autogen-agent@lobstermail.ai

For AutoGen, you'd wrap this as a callable tool or expose it through an MCP server. The difference from the methods above is that the agent isn't borrowing a human's Gmail. It has its own address, its own sending reputation, and security built into the infrastructure layer rather than bolted on after the fact.

If you want to try this with an AutoGen project, and paste them into your agent.

Frequently asked questions

What Python packages do I need for AutoGen email integration?

For Composio, install composio-autogen. For direct SMTP, install autogen-ext-email. For MCP, you need autogen-ext plus a compatible email MCP server running separately. Each method uses a different package with its own dependencies.

What is the difference between Composio and autogen-ext-email?

Composio manages OAuth tokens and supports multiple providers without you handling raw credentials. The autogen-ext-email package connects directly to SMTP/IMAP servers using passwords you supply. Composio is faster to set up; autogen-ext-email gives you more control over the connection.

How do I securely store email credentials in an AutoGen agent?

Never hardcode passwords in source files. Use environment variables (os.environ["EMAIL_PASSWORD"]) or a dedicated secrets manager like HashiCorp Vault. Composio sidesteps this entirely by managing credentials through OAuth on your behalf.

Can AutoGen agents both read and send emails in the same workflow?

Yes. Both Composio and autogen-ext-email support read and send operations within a single agent run. Your agent can poll for new messages, parse the content, draft a response, and send it in one execution loop.

What SMTP and IMAP settings do I need for Gmail with AutoGen?

Gmail SMTP: smtp.gmail.com on port 587 with TLS. Gmail IMAP: imap.gmail.com on port 993 with SSL. You'll need an app password from your Google Account security settings, which requires two-factor authentication to be enabled first.

How does the MCP approach to email differ from direct SMTP?

MCP exposes email operations as discoverable tools through a protocol server. Direct SMTP means your agent's code includes mail server connection details. MCP is more flexible because you can swap providers without changing agent code, but the email MCP ecosystem is still young.

What changed between AutoGen 0.2 and 0.4 for email agents?

AutoGen 0.2 used ConversableAgent with function-call registration for tool use. AutoGen 0.4 introduced native MCP support and a cleaner AssistantAgent tool pattern. Code written for 0.2 needs restructuring to work with 0.4, especially the autogen-ext-email package which targets 0.4.9+.

How do I trigger an AutoGen agent workflow when a new email arrives?

Composio supports event-based triggers like gmail_new_gmail_message that fire when a new email lands. For SMTP/IMAP approaches, you'd poll the inbox on a timer. Most MCP email servers also require polling since push-based notification support is limited.

Is AutoGen email integration suitable for transactional email at production scale?

Not with consumer email accounts. Gmail's rate limit of 500 sends per day (2,000 for Workspace) is too low for transactional volume. Production-scale sending requires a dedicated email service with bounce handling, reputation management, and higher throughput limits.

How do I handle email attachments inside an AutoGen agent?

The autogen-ext-email package supports basic attachment parsing from received messages. With Composio, use the GMAIL_GET_ATTACHMENT action. In both cases, your agent logic needs to handle file type detection and size limits before processing.

What Gmail API rate limits should I know about for AutoGen email automation?

Gmail enforces roughly 500 sends per day for consumer accounts, 2,000 for Workspace, and per-minute quotas on API calls. Exceeding these results in 429 or 550 errors. None of the three integration methods include automatic retry logic for rate limit responses.

How does an agent-first email API reduce setup compared to raw SMTP?

An agent-first API like LobsterMail lets the agent create its own inbox programmatically. No human signup, no SMTP credentials to manage, no OAuth flow to configure. The agent calls an API, gets an email address, and starts using it immediately.

Can multiple AutoGen agents collaborate on a single email thread?

Yes, but you need to design the coordination yourself. AutoGen's group chat patterns let multiple agents discuss how to reply, but email actions like send and forward should be restricted to one designated agent to avoid sending duplicate responses.

How do I test AutoGen email agents locally without sending real emails?

Run a local SMTP server like MailHog or MailCatcher that accepts all messages without delivering them. Point your EmailConfig at localhost:1025 during development. Composio also offers sandbox modes for testing OAuth flows without touching real inboxes.

Which AutoGen email integration method is best for prototyping versus production?

Composio is fastest for prototyping because OAuth setup takes minutes and you skip credential management. For production, evaluate whether you need provider independence (MCP), direct connection control (autogen-ext-email), or agent-native inbox provisioning with built-in security scoring.

Related posts