Receive email and route it to your application
Parse messages, download attachments, and route inbound traffic via API and webhooks.
Last updated May 29, 2026
How It Works
-
Receive: Email arrives at an alias on your verified domain (e.g.,
[email protected]). -
Parse: Bavimail extracts the sender, recipients, subject, plain text, HTML body, headers, and attachments.
-
Store: The parsed message is stored and available via the API.
-
Notify: If you have a webhook subscribed to
email.inbound.received, Bavimail sends a POST to your endpoint.
Reading Messages via API
import { Bavimail } from 'bavimail'
const client = new Bavimail()
// List inbound emails for an alias (returns InboundEmailSummary[])
const messages = await client.inboundEmails.list({ aliasId: 'alias_abc123' })
for (const msg of messages) {
console.log(`From: ${msg.fromEmail}`)
console.log(`Subject: ${msg.subject}`)
console.log(`Has HTML: ${msg.hasHtml}`)
}
// Get a single message with full details (InboundEmailDetail)
const message = await client.inboundEmails.get('em_xyz789')
console.log('HTML body:', message.bodyHtml)
console.log('Attachments:', message.attachmentCount)Features
-
Parsed content: Plain text and HTML bodies extracted automatically.
-
Attachments: Files are stored and accessible via download URL. Metadata includes filename, content type, and size.
-
Headers: Full email headers preserved for debugging and routing.
-
Conversations: Messages are threaded by
In-Reply-ToandReferencesheaders for conversation tracking.
Webhook Processing
Subscribe to the email.inbound.received event to process messages in real time:
{
"event_id": "evt_abc123",
"event_type": "email.inbound.received",
"timestamp": "2026-04-11T14:30:00Z",
"data": {
"email_id": "em_xyz789",
"alias_id": "alias_abc123",
"domain_id": "dom_abc123",
"from_email": "[email protected]",
"to_email": "[email protected]",
"subject": "Help with my account",
"body_preview": "Hi, I need help resetting my password...",
"has_html": true,
"attachment_count": 0,
"received_at": "2026-04-11T14:30:00Z"
}
}See the Webhooks guide for signature verification and retry behavior.
How does inbound email work?
Point an MX record at a Bavimail-verified domain or alias. When email lands, Bavimail parses headers, body (plain and HTML), and attachments, then delivers a signed webhook payload. Attachments come back as pre-signed URLs the agent can fetch directly — no giant inline blobs.
Verify your domain for production email delivery
Configure DNS records for SPF, DKIM, and DMARC with step-by-step guidance.
Signed webhook deliveries backed by the real event model
Bavimail emits outbound lifecycle events, inbound receipt events, domain verification events, and test pings. Verification should match the actual SDK helper and header contract.