Sales & outboundpattern
AgentMail outbox with webhook-driven CRM state flips
Sendgrid + IMAP polling + reply parser takes two weeks to wire. Replace with one email service built for agents; done in hours.
What
Replaces the Sendgrid + IMAP polling + custom reply-parser stack with a single email service purpose-built for AI agents. Outbound goes through client.inboxes.messages.send/reply (returns thread_id). Inbound message.received and message.bounced events fire webhooks that flip CRM rows to replied or bounced in real time, save an excerpt, and post a Telegram notification.
Why it matters
Replaces a couple of weeks of integration work with a few hours. State changes are real-time instead of "next IMAP poll", so dashboards and operator inboxes are always current.
End-to-end
- Sign up at agentmail.to, get
AGENTMAIL_API_KEYand a default inbox. pip install agentmail; instantiate the client.- Set
AGENTMAIL_WEBHOOK_SECRETand register webhook URLhttps://<host>/api/webhooks/agentmail?token=<secret>for eventsmessage.received,message.bounced. - Outbound: capture returned
message_idandthread_idper send. For replies usemessages.reply()soIn-Reply-Toheaders stay correct. - Webhook handler: verify
?token=, look up deal by recipient +thread_id, flip status, save excerpt, fire Telegram notification. - Treat
event_idas the idempotency key — replays are common.
Gotchas
- Never put the webhook secret in the payload — keep it in the query string and verify on the server. Webhook replays are routine; build the handler idempotent on
event_idfrom day one.
Tools
- AgentMail account
- Public webhook endpoint (Cloudflare tunnel works for dev)
- CRM table keyed by
(recipient, thread_id)
← All casesB-005