Connecting an AI Agent to Email via IMAP and SMTP
After connecting messaging apps and even phone calls, email turned out to be genuinely not fast. You have to open a messaging app, and phone calls cost money per minute. Email was the channel I knew best, so I connected it last. The setup was shorter than I expected. (measured on the operator's environment)
Why IMAP/SMTP
Unlike messaging apps, Hermes logs directly into the mail server to read and send. No webhooks, no websockets โ just standard email protocols that have existed for decades.
The four environment variables
EMAIL_ADDRESS=you@example.com
EMAIL_PASSWORD=your-app-password
EMAIL_IMAP_HOST=imap.example.com
EMAIL_SMTP_HOST=smtp.example.com
Trap 1: Gmail requires an app password
If you use Gmail with 2-step verification (which you should), your normal password will be rejected. Generate an app password from Google Account โ Security โ 2-Step Verification โ App passwords. The 16-character generated password is what goes into EMAIL_PASSWORD.
Trap 2: Some providers block IMAP by default
Outlook/Hotmail requires you to explicitly enable IMAP access in webmail settings before the connection works. Yahoo has similar restrictions. Check your provider's security settings before troubleshooting the connection.
Starting the gateway
hermes gateway start
The email channel registers through the same gateway as other channels. There is no separate hermes email subcommand โ email is configured through environment variables and the gateway picks it up.
What email is actually good for
Email is the slowest channel in terms of response time, but it is the most universal. Every professional contact has email. It works without the recipient having installed anything. For asynchronous work where you want the agent to process something and get back to you later, email is ideal.
Summary
- Enable IMAP/SMTP access in your email provider settings
- For Gmail, generate an app password โ normal passwords are rejected
- Set the four environment variables
hermes gateway startโ email registers through the same gateway- Email is the slowest but most universal channel
AI Knowledge Hub