Advanced Routing
Enterprise edition adds regex patterns and header-based conditions to MXHook's routing engine.
Regex Recipient Patterns
Match recipients using regular expressions for complex routing logic:
bash
curl -X POST http://localhost:8080/routes \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"domain": "yourdomain.com",
"recipient_pattern": "^ticket-\\d+@yourdomain.com$",
"webhook_url": "https://yourapp.com/tickets"
}'This matches addresses like ticket-123@yourdomain.com, ticket-9999@yourdomain.com, etc.
Examples
| Pattern | Matches |
|---|---|
^ticket-\d+@domain.com$ | ticket-123@domain.com |
^(sales|marketing)@domain.com$ | sales@domain.com, marketing@domain.com |
^.+-noreply@domain.com$ | alerts-noreply@domain.com, billing-noreply@domain.com |
Pattern Syntax
MXHook uses Go's regexp package, which implements RE2 syntax. Notable differences from PCRE:
- No backreferences
- No lookahead/lookbehind
- Linear-time matching (no catastrophic backtracking)
Header-Based Conditions
Route emails based on header values. This enables routing decisions based on metadata beyond the recipient:
bash
curl -X POST http://localhost:8080/routes \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key" \
-d '{
"domain": "yourdomain.com",
"recipient_pattern": "*@yourdomain.com",
"webhook_url": "https://yourapp.com/high-priority",
"header_conditions": {
"X-Priority": "1"
}
}'Use Cases
- Priority routing — route high-priority emails to a faster processing pipeline
- List filtering — route mailing list emails differently based on
List-Id - Source identification — route based on
X-Maileror custom headers - Auto-reply detection — filter auto-replies using
Auto-Submittedheader
Evaluation Order
When advanced routing is enabled, routes are evaluated as:
- Header conditions are checked first (if present)
- Recipient pattern is matched (exact, wildcard, plus-addressing, or regex)
- First route where both conditions match wins