or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration-sets.mdemail-sending.mdidentity-management.mdindex.mdreceipt-processing.mdstatistics-monitoring.mdtemplate-management.mdutilities.md
tile.json

receipt-processing.mddocs/

Receipt Processing

Comprehensive email receipt processing system with rules, rule sets, and actions for handling incoming emails automatically. This module enables you to process incoming emails through SES with custom rules and automated actions.

Capabilities

Receipt Rules

Create and manage rules for processing incoming emails.

/**
 * Creates a receipt rule for processing incoming emails
 * @param input - Rule set name and rule definition
 * @returns Promise with operation result
 */
interface CreateReceiptRuleCommandInput {
  /** Name of rule set to add rule to */
  RuleSetName: string;
  /** Name of rule to insert after (optional) */
  After?: string;
  /** Rule definition */
  Rule: ReceiptRule;
}

interface CreateReceiptRuleCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Updates an existing receipt rule
 * @param input - Rule set name and updated rule definition
 * @returns Promise with operation result
 */
interface UpdateReceiptRuleCommandInput {
  /** Name of rule set containing the rule */
  RuleSetName: string;
  /** Updated rule definition */
  Rule: ReceiptRule;
}

interface UpdateReceiptRuleCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Deletes a receipt rule
 * @param input - Rule set and rule names
 * @returns Promise with operation result
 */
interface DeleteReceiptRuleCommandInput {
  /** Name of rule set containing the rule */
  RuleSetName: string;
  /** Name of rule to delete */
  RuleName: string;
}

interface DeleteReceiptRuleCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Gets details about a receipt rule
 * @param input - Rule set and rule names
 * @returns Promise with rule details
 */
interface DescribeReceiptRuleCommandInput {
  /** Name of rule set containing the rule */
  RuleSetName: string;
  /** Name of rule to describe */
  RuleName: string;
}

interface DescribeReceiptRuleCommandOutput {
  /** Rule definition */
  Rule?: ReceiptRule;
  $metadata: ResponseMetadata;
}

/**
 * Sets the position of a receipt rule within its rule set
 * @param input - Rule set, rule name, and position
 * @returns Promise with operation result
 */
interface SetReceiptRulePositionCommandInput {
  /** Name of rule set */
  RuleSetName: string;
  /** Name of rule to reposition */
  RuleName: string;
  /** Name of rule to insert after (omit for first position) */
  After?: string;
}

interface SetReceiptRulePositionCommandOutput {
  $metadata: ResponseMetadata;
}

Usage Example:

import { 
  SESClient, 
  CreateReceiptRuleCommand 
} from "@aws-sdk/client-ses";

const client = new SESClient({ region: "us-east-1" });

const createRuleCommand = new CreateReceiptRuleCommand({
  RuleSetName: "support-processing",
  Rule: {
    Name: "support-tickets",
    Enabled: true,
    TlsPolicy: "Require",
    Recipients: ["support@company.com", "help@company.com"],
    Actions: [
      {
        S3Action: {
          BucketName: "email-storage",
          ObjectKeyPrefix: "support/",
          TopicArn: "arn:aws:sns:us-east-1:123456789012:new-support-email",
        },
      },
      {
        LambdaAction: {
          FunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:ProcessSupportEmail",
          InvocationType: "Event",
        },
      },
    ],
    ScanEnabled: true,
  },
});

await client.send(createRuleCommand);
console.log("Support email processing rule created");

Receipt Rule Sets

Manage collections of receipt rules.

/**
 * Creates a receipt rule set
 * @param input - Rule set name
 * @returns Promise with operation result
 */
interface CreateReceiptRuleSetCommandInput {
  /** Name of rule set to create */
  RuleSetName: string;
}

interface CreateReceiptRuleSetCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Deletes a receipt rule set and all its rules
 * @param input - Rule set name to delete
 * @returns Promise with operation result
 */
interface DeleteReceiptRuleSetCommandInput {
  /** Name of rule set to delete */
  RuleSetName: string;
}

interface DeleteReceiptRuleSetCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Creates a copy of an existing rule set
 * @param input - Source and destination rule set names
 * @returns Promise with operation result
 */
interface CloneReceiptRuleSetCommandInput {
  /** Name of rule set to clone */
  RuleSetName: string;
  /** Name for the new rule set */
  OriginalRuleSetName: string;
}

interface CloneReceiptRuleSetCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Gets details about a receipt rule set
 * @param input - Rule set name
 * @returns Promise with rule set details
 */
interface DescribeReceiptRuleSetCommandInput {
  /** Name of rule set to describe */
  RuleSetName: string;
}

interface DescribeReceiptRuleSetCommandOutput {
  /** Rule set metadata */
  Metadata?: ReceiptRuleSetMetadata;
  /** List of rules in the set */
  Rules?: ReceiptRule[];
  $metadata: ResponseMetadata;
}

/**
 * Lists all receipt rule sets
 * @param input - Optional pagination parameters
 * @returns Promise with rule set list
 */
interface ListReceiptRuleSetsCommandInput {
  /** Token for pagination */
  NextToken?: string;
}

interface ListReceiptRuleSetsCommandOutput {
  /** List of rule sets */
  RuleSets?: ReceiptRuleSetMetadata[];
  /** Token for next page of results */
  NextToken?: string;
  $metadata: ResponseMetadata;
}

/**
 * Sets the active receipt rule set
 * @param input - Rule set name to activate
 * @returns Promise with operation result
 */
interface SetActiveReceiptRuleSetCommandInput {
  /** Name of rule set to activate (null to deactivate all) */
  RuleSetName?: string;
}

interface SetActiveReceiptRuleSetCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Gets information about the active receipt rule set
 * @param input - Empty input
 * @returns Promise with active rule set details
 */
interface DescribeActiveReceiptRuleSetCommandInput {}

interface DescribeActiveReceiptRuleSetCommandOutput {
  /** Active rule set metadata */
  Metadata?: ReceiptRuleSetMetadata;
  /** Rules in the active rule set */
  Rules?: ReceiptRule[];
  $metadata: ResponseMetadata;
}

/**
 * Reorders rules within a rule set
 * @param input - Rule set name and new rule order
 * @returns Promise with operation result
 */
interface ReorderReceiptRuleSetCommandInput {
  /** Name of rule set to reorder */
  RuleSetName: string;
  /** List of rule names in desired order */
  RuleNames: string[];
}

interface ReorderReceiptRuleSetCommandOutput {
  $metadata: ResponseMetadata;
}

Receipt Filters

Manage IP address filters for incoming emails.

/**
 * Creates an IP address filter for incoming emails
 * @param input - Filter definition
 * @returns Promise with operation result
 */
interface CreateReceiptFilterCommandInput {
  /** Filter definition */
  Filter: ReceiptFilter;
}

interface CreateReceiptFilterCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Deletes an IP address filter
 * @param input - Filter name to delete
 * @returns Promise with operation result
 */
interface DeleteReceiptFilterCommandInput {
  /** Name of filter to delete */
  FilterName: string;
}

interface DeleteReceiptFilterCommandOutput {
  $metadata: ResponseMetadata;
}

/**
 * Lists all IP address filters
 * @param input - Empty input
 * @returns Promise with filter list
 */
interface ListReceiptFiltersCommandInput {}

interface ListReceiptFiltersCommandOutput {
  /** List of receipt filters */
  Filters?: ReceiptFilter[];
  $metadata: ResponseMetadata;
}

Core Types

Receipt Rules

interface ReceiptRule {
  /** Unique rule name */
  Name: string;
  /** Whether the rule is enabled */
  Enabled?: boolean;
  /** TLS requirement policy */
  TlsPolicy?: TlsPolicy;
  /** List of recipient email addresses */
  Recipients?: string[];
  /** List of actions to perform */
  Actions?: ReceiptAction[];
  /** Whether to scan for spam and viruses */
  ScanEnabled?: boolean;
}

interface ReceiptRuleSetMetadata {
  /** Rule set name */
  Name?: string;
  /** Creation timestamp */
  CreatedTimestamp?: Date;
}

type TlsPolicy = "Require" | "Optional";

Receipt Actions

interface ReceiptAction {
  /** Store email in S3 bucket */
  S3Action?: S3Action;
  /** Bounce the email */
  BounceAction?: BounceAction;
  /** Invoke Lambda function */
  LambdaAction?: LambdaAction;
  /** Publish to SNS topic */
  SNSAction?: SNSAction;
  /** Add header to email */
  AddHeaderAction?: AddHeaderAction;
  /** Forward to WorkMail */
  WorkmailAction?: WorkmailAction;
  /** Stop processing rules */
  StopAction?: StopAction;
}

interface S3Action {
  /** S3 bucket name */
  BucketName: string;
  /** Object key prefix */
  ObjectKeyPrefix?: string;
  /** SNS topic to notify */
  TopicArn?: string;
  /** KMS key for encryption */
  KmsKeyArn?: string;
}

interface BounceAction {
  /** SNS topic for notification */
  TopicArn?: string;
  /** SMTP reply code */
  SmtpReplyCode: string;
  /** Status code */
  StatusCode?: string;
  /** Bounce message */
  Message: string;
  /** Sender of bounce message */
  Sender: string;
}

interface LambdaAction {
  /** Lambda function ARN */
  FunctionArn: string;
  /** Invocation type */
  InvocationType?: InvocationType;
  /** SNS topic for notification */
  TopicArn?: string;
}

interface SNSAction {
  /** SNS topic ARN */
  TopicArn: string;
  /** Message encoding */
  Encoding?: SNSActionEncoding;
}

interface AddHeaderAction {
  /** Header name */
  HeaderName: string;
  /** Header value */
  HeaderValue: string;
}

interface WorkmailAction {
  /** WorkMail organization ARN */
  OrganizationArn: string;
  /** SNS topic for notification */
  TopicArn?: string;
}

interface StopAction {
  /** Scope of stop action */
  Scope: StopScope;
  /** SNS topic for notification */
  TopicArn?: string;
}

type InvocationType = "Event" | "RequestResponse";
type SNSActionEncoding = "UTF_8" | "Base64";
type StopScope = "RuleSet";

Receipt Filters

interface ReceiptFilter {
  /** Filter name */
  Name: string;
  /** IP filter definition */
  IpFilter: ReceiptIpFilter;
}

interface ReceiptIpFilter {
  /** Filter policy */
  Policy: ReceiptFilterPolicy;
  /** CIDR IP address range */
  Cidr: string;
}

type ReceiptFilterPolicy = "Block" | "Allow";

Error Handling

class RuleDoesNotExistException extends SESServiceException {
  name: "RuleDoesNotExistException";
}

class RuleSetDoesNotExistException extends SESServiceException {
  name: "RuleSetDoesNotExistException";
}

class AlreadyExistsException extends SESServiceException {
  name: "AlreadyExistsException";
}

class CannotDeleteException extends SESServiceException {
  name: "CannotDeleteException";
}

class InvalidLambdaFunctionException extends SESServiceException {
  name: "InvalidLambdaFunctionException";
}

class InvalidS3ConfigurationException extends SESServiceException {
  name: "InvalidS3ConfigurationException";
}

class InvalidSnsTopicException extends SESServiceException {
  name: "InvalidSnsTopicException";
}

class LimitExceededException extends SESServiceException {
  name: "LimitExceededException";
}

Complete Receipt Processing Setup Example:

import { 
  SESClient, 
  CreateReceiptRuleSetCommand,
  CreateReceiptRuleCommand,
  CreateReceiptFilterCommand,
  SetActiveReceiptRuleSetCommand 
} from "@aws-sdk/client-ses";

const client = new SESClient({ region: "us-east-1" });

// 1. Create rule set
await client.send(new CreateReceiptRuleSetCommand({
  RuleSetName: "customer-emails",
}));

// 2. Create IP filter to block spam
await client.send(new CreateReceiptFilterCommand({
  Filter: {
    Name: "block-spam-network",
    IpFilter: {
      Policy: "Block",
      Cidr: "192.0.2.0/24", // Example spam network
    },
  },
}));

// 3. Create rule for support emails
await client.send(new CreateReceiptRuleCommand({
  RuleSetName: "customer-emails",
  Rule: {
    Name: "support-processing",
    Enabled: true,
    TlsPolicy: "Optional",
    Recipients: ["support@company.com"],
    Actions: [
      // Store in S3 for archival
      {
        S3Action: {
          BucketName: "company-support-emails",
          ObjectKeyPrefix: "incoming/",
          TopicArn: "arn:aws:sns:us-east-1:123456789012:support-email-received",
        },
      },
      // Process with Lambda
      {
        LambdaAction: {
          FunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:CreateSupportTicket",
          InvocationType: "Event",
        },
      },
    ],
    ScanEnabled: true,
  },
}));

// 4. Create rule for sales inquiries
await client.send(new CreateReceiptRuleCommand({
  RuleSetName: "customer-emails",
  After: "support-processing",
  Rule: {
    Name: "sales-inquiries",
    Enabled: true,
    Recipients: ["sales@company.com", "info@company.com"],
    Actions: [
      // Forward to sales team CRM
      {
        LambdaAction: {
          FunctionArn: "arn:aws:lambda:us-east-1:123456789012:function:ProcessSalesInquiry",
          InvocationType: "Event",
        },
      },
      // Add tracking header
      {
        AddHeaderAction: {
          HeaderName: "X-Lead-Source",
          HeaderValue: "Email-Inquiry",
        },
      },
    ],
  },
}));

// 5. Create catch-all rule
await client.send(new CreateReceiptRuleCommand({
  RuleSetName: "customer-emails",
  After: "sales-inquiries",
  Rule: {
    Name: "catch-all",
    Enabled: true,
    Actions: [
      // Store everything else
      {
        S3Action: {
          BucketName: "company-email-archive",
          ObjectKeyPrefix: "general/",
        },
      },
      // Stop processing other rules
      {
        StopAction: {
          Scope: "RuleSet",
        },
      },
    ],
  },
}));

// 6. Activate the rule set
await client.send(new SetActiveReceiptRuleSetCommand({
  RuleSetName: "customer-emails",
}));

console.log("Email receipt processing fully configured");

// Verify configuration
import { DescribeActiveReceiptRuleSetCommand } from "@aws-sdk/client-ses";

const activeRuleSet = await client.send(new DescribeActiveReceiptRuleSetCommand({}));
console.log("Active rule set:", activeRuleSet.Metadata?.Name);
console.log("Number of rules:", activeRuleSet.Rules?.length);