DEV Community

Kumar Deepanshu
Kumar Deepanshu

Posted on

How I built an email inbox for AI agents (OTP, bulk sending, and marketing emails)

if you've ever tried to make an AI agent fully autonomous, you've hit this wall: the agent needs to log into something, and boom, there's a 2FA/OTP email waiting.

the agent has no inbox. it can't read emails. your whole automation just... stops.

i ran into this exact problem and ended up building AgentMailr to solve it. here's what i learned and where it's going.

the core problem

most AI agent setups treat email as an afterthought. you can send emails fine, but receiving them in a way that's agent-friendly is a pain. IMAP polling adds latency and burns context. scraping webmail is fragile. forwarding to a webhook works but means you have to build and maintain the correlation logic yourself.

what i really wanted was something like this:

const otp = await inbox.waitForOtp({ timeout: 60000 })
Enter fullscreen mode Exit fullscreen mode

one call. blocks until the email arrives. returns the code. done.

how it works

each agent gets a real email address (like my-agent@agentmailr.com). when an email arrives, we parse it across plain text, HTML, and subject line to extract the most likely OTP code. the connection stays open (long-polling) so your agent doesn't have to poll.

you can also filter by sender domain so your agent doesn't accidentally grab an OTP from the wrong email:

const otp = await inbox.waitForOtp({
  timeout: 60000,
  from: 'accounts.google.com'
})
Enter fullscreen mode Exit fullscreen mode

works with LangChain, LangGraph, CrewAI, or any custom agent setup.

beyond OTP - bulk and marketing email

once you have a real email infrastructure layer for agents, a lot more becomes possible.

we're building out two more capabilities:

bulk email sending - your agent can send emails at scale. think outreach agents, notification systems, or any workflow that needs to email thousands of people without you manually managing SMTP configs or deliverability.

marketing email - full campaign support. drip sequences, newsletters, broadcast emails. the idea is your AI agent can run your entire email marketing loop, from writing the copy to sending it to the right segments, all programmatically.

so AgentMailr is becoming the full email layer for AI agents, not just the OTP receiver.

why this matters for agentic systems

most agent frameworks think of tools as "call an API, get a result". email doesn't work like that. it's async. something sends you an email and you have to wait for it, sometimes seconds, sometimes minutes.

bulk and marketing email flips it the other way: your agent needs to initiate thousands of outbound messages reliably, with tracking, with deliverability guarantees.

none of the existing email tools were built with agents as the primary user. that's the gap AgentMailr fills.

current status

  • OTP/inbox receiving: live, you can use it today
  • bulk sending: coming soon
  • marketing email / campaigns: on the roadmap

if you're building agents and running into the email problem, check it out at agentmailr.com. happy to answer questions in the comments.

Top comments (0)