Skip navigation links

Package software.amazon.awscdk.services.ses

Amazon Simple Email Service Construct Library

See: Description

Package software.amazon.awscdk.services.ses Description

Amazon Simple Email Service Construct Library

---

cfn-resources: Stable

cdk-constructs: Stable


This module is part of the AWS Cloud Development Kit project.

Email receiving

Create a receipt rule set with rules and actions (actions can be found in the @aws-cdk/aws-ses-actions package):

 import software.amazon.awscdk.services.s3.*;
 import software.amazon.awscdk.services.ses.actions.*;
 
 
 Bucket bucket = new Bucket(this, "Bucket");
 Topic topic = new Topic(this, "Topic");
 
 ReceiptRuleSet.Builder.create(this, "RuleSet")
         .rules(List.of(ReceiptRuleOptions.builder()
                 .recipients(List.of("hello@aws.com"))
                 .actions(List.of(
                     AddHeader.Builder.create()
                             .name("X-Special-Header")
                             .value("aws")
                             .build(),
                     S3.Builder.create()
                             .bucket(bucket)
                             .objectKeyPrefix("emails/")
                             .topic(topic)
                             .build()))
                 .build(), ReceiptRuleOptions.builder()
                 .recipients(List.of("aws.com"))
                 .actions(List.of(
                     Sns.Builder.create()
                             .topic(topic)
                             .build()))
                 .build()))
         .build();
 

Alternatively, rules can be added to a rule set:

 ReceiptRuleSet ruleSet = new ReceiptRuleSet(this, "RuleSet");
 
 ReceiptRule awsRule = ruleSet.addRule("Aws", ReceiptRuleOptions.builder()
         .recipients(List.of("aws.com"))
         .build());
 

And actions to rules:

 import software.amazon.awscdk.services.ses.actions.*;
 
 ReceiptRule awsRule;
 Topic topic;
 
 awsRule.addAction(Sns.Builder.create()
         .topic(topic)
         .build());
 

When using addRule, the new rule is added after the last added rule unless after is specified.

Drop spams

A rule to drop spam can be added by setting dropSpam to true:

 ReceiptRuleSet.Builder.create(this, "RuleSet")
         .dropSpam(true)
         .build();
 

This will add a rule at the top of the rule set with a Lambda action that stops processing messages that have at least one spam indicator. See Lambda Function Examples.

Receipt filter

Create a receipt filter:

 ReceiptFilter.Builder.create(this, "Filter")
         .ip("1.2.3.4/16")
         .build();
 

An allow list filter is also available:

 AllowListReceiptFilter.Builder.create(this, "AllowList")
         .ips(List.of("10.0.0.0/16", "1.2.3.4/16"))
         .build();
 

This will first create a block all filter and then create allow filters for the listed ip addresses.

Skip navigation links