View a markdown version of this page

Rule set examples - Amazon Simple Email Service

Rule set examples

Use these examples to identify the pattern that matches your email-processing goal. Each example explains which recipients or messages the rule selects, which Unless conditions exclude matches, the order in which actions run, and the expected result.

Each JSON block is a complete value for the Rules list in a CreateRuleSet or UpdateRuleSet request. The resource identifiers, addresses, and names are example values. Replace them with resources and addresses from your environment. For instructions on applying a Rules list, see Create and manage rule sets. For condition fields, action fields, permissions, and failure behavior, see Rule conditions and Rule actions.

Choose an example.

Archive and deliver email

Goal

Submit email for compliance archiving before delivering it to an existing mail server.

How the pattern works

The rule selects recipients in the example.com domain, except test@example.com. Archive runs before SMTP relay, so Mail Manager accepts the archive request before relay starts. This order does not confirm that durable archive storage has completed.

Rule configuration

The rule uses the following conditions and ordered actions.

  • Conditions – RECIPIENT ENDS_WITH @example.com.

  • Unless – RECIPIENT EQUALS test@example.com.

  • Actions

    1. Archive in a-1a2b3c4d5e6f.

    2. Relay through rl-0123456789abcdef.

Literal configuration

The following Rules list implements the pattern.

[ { "Name": "archive-and-relay-orders", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "ENDS_WITH", "Values": [ "@example.com" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "test@example.com" ] } } ], "Actions": [ { "Archive": { "TargetArchive": "a-1a2b3c4d5e6f" } }, { "Relay": { "Relay": "rl-0123456789abcdef", "MailFrom": "REPLACE", "ActionFailurePolicy": "DROP" } } ] } ]
Expected result

For an email addressed to orders@example.com and test@example.com, the Archive and Relay actions run only for orders@example.com. Mail Manager accepts the archive request before relay starts. This result does not confirm that durable storage has completed. The rule takes no action for test@example.com, which remains available to later rules.

Related AWS walkthrough

For a complete in-transit archiving and SMTP delivery walkthrough, see Archiving and sending to final SMTP server.

Related details

See SMTP connection and envelope conditions for recipient matching. See How action order works, Archive, SMTP relay, and Handling an action failure for action configuration and behavior.

Isolate suspicious email

Goal

Store suspicious email for security review and prevent it from reaching its selected recipients.

How the pattern works

This pattern uses Vade Advanced Email Security, an Email Add On. The condition matches the addon.verdict result when Vade reports scam, suspect, phishing, or malware. A subject containing Action required skips this rule. For a match, the actions add a result header, store the email in S3, and then stop processing.

Rule configuration

The rule uses the following condition, exception, and ordered actions.

  • Conditions – Vade addon.verdict EQUALS scam, suspect, phishing, or malware.

  • Unless – SUBJECT CONTAINS Action required.

  • Actions

    1. Add X-vedacheck: failed.

    2. Write the email to the security-review prefix in mail-quarantine-example.

    3. Drop the selected recipients.

Literal configuration

The following Rules list implements the pattern.

[ { "Name": "scan-and-isolate", "Conditions": [ { "StringExpression": { "Evaluate": { "Analysis": { "Analyzer": "arn:aws:ses:us-east-1:111122223333:addon-instance/ai-0123456789abcdef", "ResultField": "addon.verdict" } }, "Operator": "EQUALS", "Values": [ "scam", "suspect", "phishing", "malware" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "Attribute": "SUBJECT" }, "Operator": "CONTAINS", "Values": [ "Action required" ] } } ], "Actions": [ { "AddHeader": { "HeaderName": "X-vedacheck", "HeaderValue": "failed" } }, { "WriteToS3": { "RoleArn": "arn:aws:iam::111122223333:role/MailManagerS3ActionRole", "S3Bucket": "mail-quarantine-example", "S3Prefix": "security-review", "ActionFailurePolicy": "DROP" } }, { "Drop": {} } ] } ]
Expected result

For an email to student@example.edu with subject Quarterly account notice and Vade verdict phishing, the stored email contains X-vedacheck: failed. After storage completes, Drop stops all remaining rule-set processing for student@example.edu.

For an email with subject Action required: reset account, the Unless condition matches. None of this rule's actions run, and the recipient remains available to later rules.

Related AWS walkthrough

This pattern follows the Scan and isolate malicious content rule in Streamlining outbound emails with SES Mail Manager. For additional security scenarios, see How SES Mail Manager Elevates Email Security and Efficiency.

Related details

See Email Add On result conditions and Email Add Ons for Email Add On conditions. See Add header, Write to S3, and Drop for the action fields and behavior.

Process email with Lambda

Goal

Invoke an application when a tenant submits documents through its dedicated email address.

How the pattern works

The recipient condition selects email sent to acme@uploads.anycompany.io. A subject beginning with [TEST] skips the invocation. The Lambda action invokes ProcessInboundAttachments asynchronously for the selected recipient.

Rule configuration

The rule uses the following condition, exception, and action.

  • Conditions – RECIPIENT EQUALS acme@uploads.anycompany.io.

  • Unless – SUBJECT STARTS_WITH [TEST].

  • Actions

    1. Invoke ProcessInboundAttachments with invocation type EVENT.

Literal configuration

The following Rules list implements the pattern.

[ { "Name": "process-acme-uploads", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "acme@uploads.anycompany.io" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "Attribute": "SUBJECT" }, "Operator": "STARTS_WITH", "Values": [ "[TEST]" ] } } ], "Actions": [ { "InvokeLambda": { "FunctionArn": "arn:aws:lambda:us-east-1:111122223333:function:ProcessInboundAttachments", "InvocationType": "EVENT", "RoleArn": "arn:aws:iam::111122223333:role/MailManagerLambdaActionRole", "ActionFailurePolicy": "DROP" } } ] } ]
Expected result

For an email with subject Invoice 1042 addressed to acme@uploads.anycompany.io and globex@uploads.anycompany.io, the function receives one asynchronous invocation for acme@uploads.anycompany.io. The rule does not select globex@uploads.anycompany.io.

If the subject is [TEST] Invoice 1042, the Unless condition skips the invocation.

Related AWS walkthrough

For a multi-tenant attachment-processing example, see Build an AI email pipeline with Amazon Bedrock and SES Mail Manager.

Related details

See Recipient-level and message-level matching for recipient and subject behavior. See Invoke Lambda function for the payload, permissions, invocation types, responses, and failure behavior.

Route email by department

Goal

Send sales and support recipients to separate departmental mail systems.

How the pattern works

Two ordered rules evaluate each SMTP envelope recipient separately. The first rule sends sales@example.com through the sales relay. The second rule sends support@example.com through the support relay. Both rules exclude messages from the automated test sender.

Rule configuration

The rule set uses the following rules.

  • Rule 1

    • Conditions – RECIPIENT EQUALS sales@example.com.

    • Unless – MAIL_FROM EQUALS automated-test@example.net.

    • Actions – Relay through rl-0123456789abcdef.

  • Rule 2

    • Conditions – RECIPIENT EQUALS support@example.com.

    • Unless – MAIL_FROM EQUALS automated-test@example.net.

    • Actions – Relay through rl-fedcba9876543210.

Literal configuration

The following Rules list implements the pattern.

[ { "Name": "route-sales", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "sales@example.com" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "Attribute": "MAIL_FROM" }, "Operator": "EQUALS", "Values": [ "automated-test@example.net" ] } } ], "Actions": [ { "Relay": { "Relay": "rl-0123456789abcdef", "MailFrom": "REPLACE", "ActionFailurePolicy": "DROP" } } ] }, { "Name": "route-support", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "support@example.com" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "Attribute": "MAIL_FROM" }, "Operator": "EQUALS", "Values": [ "automated-test@example.net" ] } } ], "Actions": [ { "Relay": { "Relay": "rl-fedcba9876543210", "MailFrom": "REPLACE", "ActionFailurePolicy": "DROP" } } ] } ]
Expected result

For an email from customer@example.net addressed to both sales@example.com and support@example.com, the first rule relays only sales@example.com. The second rule then relays only support@example.com.

For an email from automated-test@example.net, both Unless conditions match and neither relay action runs.

Related AWS walkthrough

For recipient-oriented processing and condition-based SMTP relay patterns, see Mail Manager – SES introduces new email routing and archiving features.

Related details

See SMTP connection and envelope conditions for RECIPIENT and MAIL_FROM. See SMTP relay for relay configuration, permissions, and delivery behavior.

Add routing information

Goal

Add routing information for one recipient before relaying the email.

How the pattern works

The recipient condition selects orders@example.com. An original X-Route: manual header skips the rule. Otherwise, Add header adds X-Route: orders before SMTP relay. The relay action receives the modified MIME email.

Rule configuration

The rule uses the following condition, exception, and ordered actions.

  • Conditions – RECIPIENT EQUALS orders@example.com.

  • Unless – Custom header X-Route EQUALS manual.

  • Actions

    1. Add X-Route: orders.

    2. Relay through rl-0123456789abcdef.

Literal configuration

The following Rules list implements the pattern.

[ { "Name": "mark-and-route-orders", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "orders@example.com" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "MimeHeaderAttribute": "X-Route" }, "Operator": "EQUALS", "Values": [ "manual" ] } } ], "Actions": [ { "AddHeader": { "HeaderName": "X-Route", "HeaderValue": "orders" } }, { "Relay": { "Relay": "rl-0123456789abcdef", "MailFrom": "REPLACE", "ActionFailurePolicy": "DROP" } } ] } ]
Expected result

For an email addressed to orders@example.com and audit@example.com without an original X-Route header, the relayed email for orders@example.com contains:

X-Route: orders

The rule does not select audit@example.com, so its email variant does not receive the header. If the original email contains X-Route: manual, the Unless condition skips both actions for orders@example.com.

Related AWS walkthrough

For the recipient-oriented header pattern that applies a change only to matching recipients, see Mail Manager – SES introduces new email routing and archiving features.

Related details

See Message header and metadata conditions for matching an original custom header. See Add header and SMTP relay for the action fields and ordering behavior.

Replace recipients during migration

Goal

Move an old email address to a new mail platform while excluding a migration test address.

How the pattern works

The first rule selects recipients in old.example.com, except migration-test@old.example.com. Replace recipient changes orders@old.example.com to orders@new.example.com. The next action associates X-Migration-Route: new-platform with the replacement recipient. A later rule matches the updated recipient and relays it to the new mail system.

Rule configuration

The rule set uses the following rules.

  • Rule 1

    • Conditions – RECIPIENT ENDS_WITH @old.example.com.

    • Unless – RECIPIENT EQUALS migration-test@old.example.com.

    • Actions

      1. Replace the selected recipient with orders@new.example.com.

      2. Add X-Migration-Route: new-platform.

  • Rule 2

    • Conditions – RECIPIENT EQUALS orders@new.example.com.

    • Unless – None.

    • Actions – Relay through rl-fedcba9876543210.

Literal configuration

The following Rules list implements the pattern.

[ { "Name": "replace-old-orders", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "ENDS_WITH", "Values": [ "@old.example.com" ] } } ], "Unless": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "migration-test@old.example.com" ] } } ], "Actions": [ { "ReplaceRecipient": { "ReplaceWith": [ "orders@new.example.com" ] } }, { "AddHeader": { "HeaderName": "X-Migration-Route", "HeaderValue": "new-platform" } } ] }, { "Name": "route-new-orders", "Conditions": [ { "StringExpression": { "Evaluate": { "Attribute": "RECIPIENT" }, "Operator": "EQUALS", "Values": [ "orders@new.example.com" ] } } ], "Unless": [], "Actions": [ { "Relay": { "Relay": "rl-fedcba9876543210", "MailFrom": "REPLACE", "ActionFailurePolicy": "DROP" } } ] } ]
Expected result

For an email addressed to orders@old.example.com and migration-test@old.example.com, the first rule replaces only orders@old.example.com. Its Add header action then applies to orders@new.example.com.

The second rule evaluates the updated recipient list. It matches orders@new.example.com and relays that recipient with:

X-Migration-Route: new-platform

migration-test@old.example.com remains unchanged and does not match the second rule. Replacing the SMTP envelope recipient does not change orders@old.example.com in the visible To or CC header.

Related AWS walkthrough

For modifying recipient lists, routing by recipient, and supporting old and new mail platforms during migration, see Mail Manager – SES introduces new email routing and archiving features.

Related details

See Recipient-level and message-level matching for recipient selection. See Replace recipient, Add header, and SMTP relay for action behavior.

Apply and monitor a rule-set pattern

Use Create and manage rule sets to create or update a rule set with one of these Rules lists and assign the rule set to an ingress endpoint.

Create the resources and permissions required by each action before applying the rule set. See Rule actions for the required resources, permissions, and failure behavior.

Use Monitor and troubleshoot rule sets to confirm successful processing and investigate an individual message. Use Setting up Mail Manager log delivery to configure logs. See Rule set logs – APPLICATION_LOGS to review which recipients matched each rule and the status and order of its actions.