Email API for agents: appending RFC 5322 copies to Sent via IMAP to fix missing outbound mail

kumard3 · reddit · 2026-11-11

A developer building an email API for agents found that sends via SES/Resend were stored in Postgres but never written to the mailbox itself, so anyone viewing an agent's inbox in a mail client saw incoming replies but none of the agent's outbound messages.

The fix: every send also builds the same RFC 5322 message with the same Message-ID and appends it to the Sent folder over IMAP, flagged as read. The append runs after the send with errors only logged, so a mail-store problem can't fail a send—at the cost of an occasional missing Sent copy. A rerunnable backfill script handles older mail and skips Message-IDs already in Sent.

Original post →

More from coding & agent

coding & agent channel →