Receive email and route it to your application

Parse messages, download attachments, and route inbound traffic via API and webhooks.

Last updated May 7, 2026

How It Works

  1. Receive: Email arrives at an alias on your verified domain (e.g., support@mail.yourcompany.com).
  2. Parse: Bavimail extracts the sender, recipients, subject, plain text, HTML body, headers, and attachments.
  3. Store: The parsed message is stored and available via the API.
  4. 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-To and References headers 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": "sender@example.com",
    "to_email": "support@mail.yourcompany.com",
    "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.