Route Matching & Expressions
How to use expression types, wildcards, Golang regex, and custom expressions to match incoming emails in Maileroo Inbound Routing.
Expression Types
When creating a route, you can choose from several expression types to filter or match incoming emails:
- Catch All — Matches all emails sent to your domain.
- Match Header — Matches emails based on specific header values.
- Match Recipient — Matches emails based on recipient addresses.
- Custom Expression — Allows advanced, combined expressions for precise control.
For both "Match Header" and "Match Recipient," you can provide a literal value, wildcard string or a regex. Literal values are compared case-insensitively, while regex offers complete flexibility.
Wildcards
When using a wildcard string, you can specify values such as *@gmail.com or maileroo@* to match values. You may even use a pattern such as *@maileroo.com to match any address ending with @maileroo.com, or admin@* to match any address starting with admin@.
Golang Regex
We use Golang RegExp syntax, allowing you to match headers or recipients in emails. For example, the following regular expression matches any string containing the case-insensitive words: Birthday, Anniversary, Celebration, Congratulations, or Event.
(?i)\b(Birthday|Anniversary|Celebration|Congratulations|Event)\bYou can learn more about it at this page.
Custom Expression
What if you wanted to match an email by both recipient and header values? This is where custom expressions come in the scene.
For example:
((match_header("Subject", `(?i)welcome.*maileroo`) || (match_recipient("[email protected]")) && match_header("From", `(?i)@gmail\.com`))This expression checks if the Subject contains "welcome" followed by "maileroo" (case-insensitive) or if the recipient is "[email protected]" and the sender's email is from a Gmail address.
You can use it to create even more complex expressions such as:
((match_header("From", `(?i)@(gmail\.com|yahoo\.com|outlook\.com)`) &&
match_header("Subject", `(?i)\b(Birthday|Anniversary|Celebration|Congratulations|Event)\b`) &&
match_header("Date", `(?i)2025-\d{2}-\d{2}`)) ||
(match_recipient("[email protected]") &&
match_header("From", `(?i)@live\.com`)))This expression checks if the email is either from Gmail, Yahoo, or Outlook with a subject containing specific celebratory terms and a date in 2025, or if the recipient is [email protected] and the sender is from Live.com.
Authentication Enforcement
You can choose to enforce DKIM and SPF on your route based on your preferences. At a minimum, we recommend ensuring that the email is DMARC-aligned.