Skip to content

ReceiptRule

Source: src/AWS/SES/ReceiptRule.ts

An Amazon SES receipt rule — a matcher plus an ordered list of actions that SES applies to inbound email received through the parent SES.ReceiptRuleSet.

Actions are passed as the raw distilled action shapes (no marshalling): the caller supplies bucket names, topic ARNs, and function ARNs directly.

Deliver Matching Mail to S3

import * as SES from "alchemy/AWS/SES";
const ruleSet = yield* SES.ReceiptRuleSet("Inbound", {});
const rule = yield* SES.ReceiptRule("ToBucket", {
ruleSetName: ruleSet.ruleSetName,
recipients: ["support@example.com"],
actions: [
{ S3Action: { BucketName: "my-inbound-mail" } },
],
});

Invoke a Lambda and Add a Header

const rule = yield* SES.ReceiptRule("Process", {
ruleSetName: ruleSet.ruleSetName,
tlsPolicy: "Require",
scanEnabled: true,
actions: [
{ AddHeaderAction: { HeaderName: "X-Inbound", HeaderValue: "ses" } },
{ LambdaAction: { FunctionArn: fn.functionArn, InvocationType: "Event" } },
],
});
// A BounceAction's Sender must be a verified SES identity — SES rejects the
// rule with IdentityNotVerified at create/update time otherwise.
const first = yield* SES.ReceiptRule("First", {
ruleSetName: ruleSet.ruleSetName,
actions: [{ StopAction: { Scope: "RuleSet" } }],
});
const second = yield* SES.ReceiptRule("Second", {
ruleSetName: ruleSet.ruleSetName,
after: first.ruleName,
actions: [{ BounceAction: {
SmtpReplyCode: "550",
Message: "Mailbox does not exist",
Sender: "mailer-daemon@example.com",
} }],
});