Email

Forward inbound email

Forward mail that arrives at your domains to outside addresses, and control which rule wins when several match.

A forwarding rule sends mail that arrives at one of your addresses on to addresses outside Samva. Each rule has a source pattern, one or more forwardTo addresses, and a priority. When a message matches more than one rule, exactly one rule forwards it.

Create a rule

forward-support.ts
import { createClient } from "samva";

const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });

await samva.email.createForwardingRule({
  name: "Support",
  domainId: "dom_abc123",
  sourcePattern: "support@example.com",
  forwardTo: ["team@example.org"],
});

sourcePattern is matched against the recipient address, ignoring case. An exact address matches only that address, * inside a pattern matches any run of characters (sales-*@example.com), and * alone, an empty pattern, or no pattern matches every address. Omit domainId to apply a rule to every domain in your organization.

Which rule wins

Samva tries rules in this order and forwards with the first rule that matches:

  1. Priority, highest first. Priority is a whole number, 0 or higher, and defaults to 0.
  2. Specificity, at equal priority. An exact address comes before a pattern with a wildcard, and a wildcard pattern with more literal characters comes before one with fewer (support-*@example.com before s*@example.com). *, an empty pattern, and no pattern come last.
  3. Age, at equal specificity. The rule created first wins.
  4. Rule ID, so the order is always the same.

With every rule at the default priority, support@example.com therefore beats *@example.com whichever you created first. Raise a rule's priority to override specificity, for example to send everything to one address during an incident.

List forwarding rules returns rules in this order, and the dashboard shows each rule's position and priority on the domain's Forwarding section. Filtering by domainId returns that domain's rules together with the rules that apply to every domain (domainId is null), which is the order mail for that domain is tried in.

Reference

Related documentation

On this page