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):

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 import software.amazon.awscdk.services.s3.*;
 import software.amazon.awscdk.services.ses.*;
 import software.amazon.awscdk.services.ses.actions.*;
 import software.amazon.awscdk.services.sns.*;
 
 Bucket bucket = new Bucket(stack, "Bucket");
 Topic topic = new Topic(stack, "Topic");
 
 new ReceiptRuleSet(stack, "RuleSet", new ReceiptRuleSetProps()
         .rules(asList(new ReceiptRuleOptions()
                 .recipients(asList("hello@aws.com"))
                 .actions(asList(
                     new AddHeader(new AddHeaderProps()
                             .name("X-Special-Header")
                             .value("aws")),
                     new S3(new S3Props()
                             .bucket(bucket)
                             .objectKeyPrefix("emails/")
                             .topic(topic)))), new ReceiptRuleOptions()
                 .recipients(asList("aws.com"))
                 .actions(asList(
                     new Sns(new SnsProps()
                             .topic(topic)))))));
 

Alternatively, rules can be added to a rule set:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 Object ruleSet = new ReceiptRuleSet(this, "RuleSet");
 
 Object awsRule = ruleSet.addRule("Aws", Map.of(
         "recipients", asList("aws.com")));
 

And actions to rules:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 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:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 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:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 ReceiptFilter.Builder.create(this, "Filter")
         .ip("1.2.3.4/16")
         .build();
 

An allow list filter is also available:

 // Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
 AllowListReceiptFilter.Builder.create(this, "AllowList")
         .ips(asList("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