Message routing enables you to automatically process inbound emails sent to your domains by forwarding them to your application endpoints in real-time. When someone sends an email to addresses on your AhaSend domains, the system can automatically parse and route these messages to your applications, making it perfect for support ticket systems, reply handling, and automated email processing workflows.
Inbound Email Processing: Message routing handles emails sent TO your domains, while webhooks track emails sent FROM your domains. Both use similar HTTP POST mechanisms but serve different purposes.

What is Message Routing?

Message routing is a powerful mechanism for efficiently managing and directing inbound email traffic within your applications. By setting up message routes, you can automatically parse and direct incoming emails to appropriate endpoints based on predefined rules or criteria. This functionality enables you to:

Support Ticket Systems

Automatically convert inbound emails into support tickets or customer inquiries

Reply Processing

Handle email replies and integrate them into existing conversation threads

Email-to-Database

Parse and store email content directly in your databases or CRM systems

Automated Workflows

Trigger application logic based on inbound email content and metadata

How Message Routes Work in AhaSend

Email Received

An email is sent to an address on your AhaSend domain (e.g., [email protected] or ticket-*@yourdomain.com)

Route Matching

AhaSend checks configured routes to find matching recipient patterns

Email Processing

The email is parsed, processed, and formatted according to your route settings

HTTP Request Sent

AhaSend sends a POST request to your endpoint URL with the email data
MX Record Requirement: Message routing requires your domain’s MX records to point to AhaSend. Without proper MX configuration, AhaSend cannot receive emails sent to your domain.

Prerequisites

Before setting up message routing, ensure your domain is properly configured:

Creating Message Routes

Configure message routes in your AhaSend dashboard to start processing inbound emails:
Screenshot of the form for creating a new route

Access Message Routing

  1. Log in to your AhaSend Dashboard
  2. Navigate to the Routes section from the main menu
  3. Click the “Add Route” button

Configure Endpoint URL

Enter Your Endpoint URL:
  • Provide the complete URL where you want to receive routing events
  • Must be a valid HTTPS URL (HTTP allowed for development)
  • Should respond with 2xx status codes for successful processing
Example URLs:
https://api.yourapp.com/inbound-email
https://yourapp.com/api/support/tickets

Set Recipient Pattern

Configure Email Address Routing:Choose the email addresses to route using the recipient email address field:Specific Address:Wildcard Patterns:
Start Specific: Begin with specific addresses like “support” or “info” before using broad wildcards like ”*” to avoid overwhelming your endpoint.

Configure Processing Options

Customize how emails are processed:

Create and Secure Route

  1. Click “Create Route” to save your configuration
  2. Note the Route Secret displayed on the details page
  3. Copy and store the secret securely for signature verification
Save Your Secret: The route secret is shown only once. Store it securely in your application’s configuration for webhook signature verification.

Testing Message Routes

Verify your message routing integration works correctly:

Use Test Events

  1. Go to your message route details page in the dashboard
  2. Click “Send Test Event”
  3. Verify your endpoint receives the test payload
Test events contain realistic sample data and arrive within seconds.

Development Tools

For Quick Testing:
  • Use Beeceptor to create temporary endpoint URLs
  • Inspect incoming requests and verify payload structure
  • Test without writing application code first
For Development:
  • Use ngrok to expose local development servers
  • Test routing handling in your actual application code

Send Real Emails

Test with Actual Email Delivery:
  1. Ensure your domain’s MX records point to AhaSend
  2. Send an email to your configured address pattern
  3. Verify your endpoint receives the routing request
  4. Check the email content and metadata are correct
Test Email Sources: Try sending from different email providers (Gmail, Outlook, etc.) to test various email formats and edge cases.

Security and Verification

Message routing follows the Standard Webhooks specification for secure payload delivery:

Security Headers

Every routing request includes the same security headers as webhooks:
webhook-id: wh_1234567890abcdef
webhook-timestamp: 1683360000
webhook-signature: v1,g0hM9SsE+OTPJTGt/tmIKtSyZlE3uFJELVlNIOLJ1OE=

Signature Verification

Use Standard Webhooks libraries to verify routing request authenticity:
import { Webhook } from 'standardwebhooks';

const webhook = new Webhook(process.env.ROUTE_SECRET, { format: 'raw' });

// In your routing handler
export async function handleInboundEmail(request) {
  const payload = await request.text();
  const headers = {
    'webhook-id': request.headers.get('webhook-id'),
    'webhook-timestamp': request.headers.get('webhook-timestamp'),
    'webhook-signature': request.headers.get('webhook-signature')
  };

  try {
    const routingEvent = webhook.verify(payload, headers);
    // Process verified inbound email
    console.log('From:', routingEvent.data.from);
    console.log('Subject:', routingEvent.data.subject);

    // Create support ticket, process reply, etc.
    await processInboundEmail(routingEvent.data);

    return new Response('OK', { status: 200 });
  } catch (error) {
    return new Response('Invalid signature', { status: 400 });
  }
}
Standard Webhooks Compatibility: Message routing uses the same Standard Webhooks libraries as regular webhooks, so you can use the same verification code for both.

Message Route Payload Structure

All message routing requests follow the Standard Webhooks payload format:
{
  "type": "message.routing",
  "timestamp": "2024-05-07T10:41:45.026792973Z",
  "data": {
    // Inbound email data
  }
}

Complete Payload Example

{
  "type": "message.routing",
  "timestamp": "2024-05-07T10:41:45.026792973Z",
  "data": {
    "id": "route-msg-12345",
    "from": "[email protected]",
    "reply_to": "[email protected]",
    "to": "[email protected]",
    "subject": "Help with my account",
    "message_id": "<[email protected]>",
    "size": 2048,
    "spam_score": 0.1,
    "bounce": false,
    "cc": "",
    "date": "Mon, 06 May 2024 13:15:46 +0000",
    "in_reply_to": "",
    "references": "",
    "auto_submitted": "",
    "html_body": "<p>I need help with my account settings.</p>",
    "plain_body": "I need help with my account settings.",
    "reply_from_plain_body": "I need help with my account settings.",
    "attachments": [
      {
        "filename": "screenshot.png",
        "content_type": "image/png",
        "content_id": "attachment_001",
        "data": "base64-encoded-image-data"
      }
    ],
    "headers": {
      "From": "[email protected]",
      "To": "[email protected]",
      "Subject": "Help with my account",
      "Date": "Mon, 06 May 2024 13:15:46 +0000",
      "Message-ID": "<[email protected]>",
      "Content-Type": "text/html; charset=UTF-8"
    }
  }
}

Key Fields Explained

Common Use Cases

Best Practices

Troubleshooting