Package software.amazon.awscdk.services.ses
Amazon Simple Email Service Construct Library
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-lib/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.
Email sending
Dedicated IP pools
When you create a new Amazon SES account, your emails are sent from IP addresses that are shared with other Amazon SES users. For an additional monthly charge, you can lease dedicated IP addresses that are reserved for your exclusive use.
Use the DedicatedIpPool construct to create a pool of dedicated IP addresses. When specifying a name for your dedicated IP pool, ensure that it adheres to the following naming convention:
- The name must include only lowercase letters (a-z), numbers (0-9), underscores (_), and hyphens (-).
- The name must not exceed 64 characters in length.
DedicatedIpPool.Builder.create(this, "Pool") .dedicatedIpPoolName("mypool") .scalingMode(ScalingMode.STANDARD) .build();
The pool can then be used in a configuration set. If the provided dedicatedIpPoolName does not follow the specified naming convention, an error will be thrown.
Configuration sets
Configuration sets are groups of rules that you can apply to your verified identities. A verified identity is a domain, subdomain, or email address you use to send email through Amazon SES. When you apply a configuration set to an email, all of the rules in that configuration set are applied to the email.
Use the ConfigurationSet
construct to create a configuration set:
IDedicatedIpPool myPool; ConfigurationSet.Builder.create(this, "ConfigurationSet") .customTrackingRedirectDomain("track.cdk.dev") .suppressionReasons(SuppressionReasons.COMPLAINTS_ONLY) .tlsPolicy(ConfigurationSetTlsPolicy.REQUIRE) .dedicatedIpPool(myPool) .build();
Use addEventDestination()
to publish email sending events to Amazon SNS or Amazon CloudWatch:
ConfigurationSet myConfigurationSet; Topic myTopic; myConfigurationSet.addEventDestination("ToSns", ConfigurationSetEventDestinationOptions.builder() .destination(EventDestination.snsTopic(myTopic)) .build());
Email identity
In Amazon SES, a verified identity is a domain or email address that you use to send or receive email. Before you
can send an email using Amazon SES, you must create and verify each identity that you're going to use as a From
,
Source
, Sender
, or Return-Path
address. Verifying an identity with Amazon SES confirms that you own it and
helps prevent unauthorized use.
To verify an identity for a hosted zone, you create an EmailIdentity
:
IPublicHostedZone myHostedZone; EmailIdentity identity = EmailIdentity.Builder.create(this, "Identity") .identity(Identity.publicHostedZone(myHostedZone)) .mailFromDomain("mail.cdk.dev") .build();
By default, Easy DKIM with a 2048-bit DKIM key is used.
You can instead configure DKIM authentication by using your own public-private key pair. This process is known as Bring Your Own DKIM (BYODKIM):
IPublicHostedZone myHostedZone; EmailIdentity.Builder.create(this, "Identity") .identity(Identity.publicHostedZone(myHostedZone)) .dkimIdentity(DkimIdentity.byoDkim(ByoDkimOptions.builder() .privateKey(SecretValue.secretsManager("dkim-private-key")) .publicKey("...base64-encoded-public-key...") .selector("selector") .build())) .build();
When using publicHostedZone()
for the identity, all necessary Amazon Route 53 records are created automatically:
- CNAME records for Easy DKIM
- TXT record for BYOD DKIM
- MX and TXT records for the custom MAIL FROM
When working with domain()
, records must be created manually:
EmailIdentity identity = EmailIdentity.Builder.create(this, "Identity") .identity(Identity.domain("cdk.dev")) .build(); for (Object record : identity.getDkimRecords()) { }
Grants
To grant a specific action to a principal use the grant
method.
For sending emails, grantSendEmail
can be used instead:
import software.amazon.awscdk.services.iam.*; User user; EmailIdentity identity = EmailIdentity.Builder.create(this, "Identity") .identity(Identity.domain("cdk.dev")) .build(); identity.grantSendEmail(user);
Virtual Deliverability Manager (VDM)
Virtual Deliverability Manager is an Amazon SES feature that helps you enhance email deliverability, like increasing inbox deliverability and email conversions, by providing insights into your sending and delivery data, and giving advice on how to fix the issues that are negatively affecting your delivery success rate and reputation.
Use the VdmAttributes
construct to configure the Virtual Deliverability Manager for your account:
// Enables engagement tracking and optimized shared delivery by default // Enables engagement tracking and optimized shared delivery by default new VdmAttributes(this, "Vdm");
-
ClassDescriptionAddHeaderAction configuration.A builder for
AddHeaderActionConfig
An implementation forAddHeaderActionConfig
An allow list receipt filter.A fluent builder forAllowListReceiptFilter
.Construction properties for am AllowListReceiptFilter.A builder forAllowListReceiptFilterProps
An implementation forAllowListReceiptFilterProps
BoundAction configuration.A builder forBounceActionConfig
An implementation forBounceActionConfig
Options for BYO DKIM.A builder forByoDkimOptions
An implementation forByoDkimOptions
Configuration sets let you create groups of rules that you can apply to the emails you send using Amazon SES.A fluent builder forCfnConfigurationSet
.Settings for your VDM configuration as applicable to the Dashboard.A builder forCfnConfigurationSet.DashboardOptionsProperty
An implementation forCfnConfigurationSet.DashboardOptionsProperty
Specifies whether messages that use the configuration set are required to use Transport Layer Security (TLS).A builder forCfnConfigurationSet.DeliveryOptionsProperty
An implementation forCfnConfigurationSet.DeliveryOptionsProperty
Settings for your VDM configuration as applicable to the Guardian.A builder forCfnConfigurationSet.GuardianOptionsProperty
An implementation forCfnConfigurationSet.GuardianOptionsProperty
Contains information about the reputation settings for a configuration set.A builder forCfnConfigurationSet.ReputationOptionsProperty
An implementation forCfnConfigurationSet.ReputationOptionsProperty
Used to enable or disable email sending for messages that use this configuration set in the current AWS Region.A builder forCfnConfigurationSet.SendingOptionsProperty
An implementation forCfnConfigurationSet.SendingOptionsProperty
An object that contains information about the suppression list preferences for your account.A builder forCfnConfigurationSet.SuppressionOptionsProperty
An implementation forCfnConfigurationSet.SuppressionOptionsProperty
A domain that is used to redirect email recipients to an Amazon SES-operated domain.A builder forCfnConfigurationSet.TrackingOptionsProperty
An implementation forCfnConfigurationSet.TrackingOptionsProperty
The Virtual Deliverability Manager (VDM) options that apply to a configuration set.A builder forCfnConfigurationSet.VdmOptionsProperty
An implementation forCfnConfigurationSet.VdmOptionsProperty
Specifies a configuration set event destination.A fluent builder forCfnConfigurationSetEventDestination
.Contains information associated with an Amazon CloudWatch event destination to which email sending events are published.An implementation forCfnConfigurationSetEventDestination.CloudWatchDestinationProperty
Contains the dimension configuration to use when you publish email sending events to Amazon CloudWatch.An implementation forCfnConfigurationSetEventDestination.DimensionConfigurationProperty
Contains information about an event destination.An implementation forCfnConfigurationSetEventDestination.EventDestinationProperty
Contains the delivery stream ARN and the IAM role ARN associated with an Amazon Kinesis Firehose event destination.An implementation forCfnConfigurationSetEventDestination.KinesisFirehoseDestinationProperty
Contains the topic ARN associated with an Amazon Simple Notification Service (Amazon SNS) event destination.An implementation forCfnConfigurationSetEventDestination.SnsDestinationProperty
Properties for defining aCfnConfigurationSetEventDestination
.A builder forCfnConfigurationSetEventDestinationProps
An implementation forCfnConfigurationSetEventDestinationProps
Properties for defining aCfnConfigurationSet
.A builder forCfnConfigurationSetProps
An implementation forCfnConfigurationSetProps
A list that contains contacts that have subscribed to a particular topic or topics.A fluent builder forCfnContactList
.An interest group, theme, or label within a list.A builder forCfnContactList.TopicProperty
An implementation forCfnContactList.TopicProperty
Properties for defining aCfnContactList
.A builder forCfnContactListProps
An implementation forCfnContactListProps
Create a new pool of dedicated IP addresses.A fluent builder forCfnDedicatedIpPool
.Properties for defining aCfnDedicatedIpPool
.A builder forCfnDedicatedIpPoolProps
An implementation forCfnDedicatedIpPoolProps
Specifies an identity for using within SES.A fluent builder forCfnEmailIdentity
.Used to associate a configuration set with an email identity.A builder forCfnEmailIdentity.ConfigurationSetAttributesProperty
An implementation forCfnEmailIdentity.ConfigurationSetAttributesProperty
Used to enable or disable DKIM authentication for an email identity.A builder forCfnEmailIdentity.DkimAttributesProperty
An implementation forCfnEmailIdentity.DkimAttributesProperty
Used to configure or change the DKIM authentication settings for an email domain identity.A builder forCfnEmailIdentity.DkimSigningAttributesProperty
An implementation forCfnEmailIdentity.DkimSigningAttributesProperty
Used to enable or disable feedback forwarding for an identity.A builder forCfnEmailIdentity.FeedbackAttributesProperty
An implementation forCfnEmailIdentity.FeedbackAttributesProperty
Used to enable or disable the custom Mail-From domain configuration for an email identity.A builder forCfnEmailIdentity.MailFromAttributesProperty
An implementation forCfnEmailIdentity.MailFromAttributesProperty
Properties for defining aCfnEmailIdentity
.A builder forCfnEmailIdentityProps
An implementation forCfnEmailIdentityProps
Specify a new IP address filter.A fluent builder forCfnReceiptFilter
.Specifies an IP address filter.A builder forCfnReceiptFilter.FilterProperty
An implementation forCfnReceiptFilter.FilterProperty
A receipt IP address filter enables you to specify whether to accept or reject mail originating from an IP address or range of IP addresses.A builder forCfnReceiptFilter.IpFilterProperty
An implementation forCfnReceiptFilter.IpFilterProperty
Properties for defining aCfnReceiptFilter
.A builder forCfnReceiptFilterProps
An implementation forCfnReceiptFilterProps
Specifies a receipt rule.An action that Amazon SES can take when it receives an email on behalf of one or more email addresses or domains that you own.A builder forCfnReceiptRule.ActionProperty
An implementation forCfnReceiptRule.ActionProperty
When included in a receipt rule, this action adds a header to the received email.A builder forCfnReceiptRule.AddHeaderActionProperty
An implementation forCfnReceiptRule.AddHeaderActionProperty
When included in a receipt rule, this action rejects the received email by returning a bounce response to the sender and, optionally, publishes a notification to Amazon Simple Notification Service (Amazon SNS).A builder forCfnReceiptRule.BounceActionProperty
An implementation forCfnReceiptRule.BounceActionProperty
A fluent builder forCfnReceiptRule
.When included in a receipt rule, this action calls an AWS Lambda function and, optionally, publishes a notification to Amazon Simple Notification Service (Amazon SNS).A builder forCfnReceiptRule.LambdaActionProperty
An implementation forCfnReceiptRule.LambdaActionProperty
Receipt rules enable you to specify which actions Amazon SES should take when it receives mail on behalf of one or more email addresses or domains that you own.A builder forCfnReceiptRule.RuleProperty
An implementation forCfnReceiptRule.RuleProperty
When included in a receipt rule, this action saves the received message to an Amazon Simple Storage Service (Amazon S3) bucket and, optionally, publishes a notification to Amazon Simple Notification Service (Amazon SNS).A builder forCfnReceiptRule.S3ActionProperty
An implementation forCfnReceiptRule.S3ActionProperty
When included in a receipt rule, this action publishes a notification to Amazon Simple Notification Service (Amazon SNS).A builder forCfnReceiptRule.SNSActionProperty
An implementation forCfnReceiptRule.SNSActionProperty
When included in a receipt rule, this action terminates the evaluation of the receipt rule set and, optionally, publishes a notification to Amazon Simple Notification Service (Amazon SNS).A builder forCfnReceiptRule.StopActionProperty
An implementation forCfnReceiptRule.StopActionProperty
When included in a receipt rule, this action calls Amazon WorkMail and, optionally, publishes a notification to Amazon Simple Notification Service (Amazon SNS).A builder forCfnReceiptRule.WorkmailActionProperty
An implementation forCfnReceiptRule.WorkmailActionProperty
Properties for defining aCfnReceiptRule
.A builder forCfnReceiptRuleProps
An implementation forCfnReceiptRuleProps
Creates an empty receipt rule set.A fluent builder forCfnReceiptRuleSet
.Properties for defining aCfnReceiptRuleSet
.A builder forCfnReceiptRuleSetProps
An implementation forCfnReceiptRuleSetProps
Specifies an email template.A fluent builder forCfnTemplate
.The content of the email, composed of a subject line and either an HTML part or a text-only part.A builder forCfnTemplate.TemplateProperty
An implementation forCfnTemplate.TemplateProperty
Properties for defining aCfnTemplate
.A builder forCfnTemplateProps
An implementation forCfnTemplateProps
The Virtual Deliverability Manager (VDM) attributes that apply to your Amazon SES account.A fluent builder forCfnVdmAttributes
.Settings for your VDM configuration as applicable to the Dashboard.A builder forCfnVdmAttributes.DashboardAttributesProperty
An implementation forCfnVdmAttributes.DashboardAttributesProperty
Settings for your VDM configuration as applicable to the Guardian.A builder forCfnVdmAttributes.GuardianAttributesProperty
An implementation forCfnVdmAttributes.GuardianAttributesProperty
Properties for defining aCfnVdmAttributes
.A builder forCfnVdmAttributesProps
An implementation forCfnVdmAttributesProps
A CloudWatch dimension upon which to categorize your emails.A builder forCloudWatchDimension
An implementation forCloudWatchDimension
Source for CloudWatch dimension.A configuration set.A fluent builder forConfigurationSet
.A configuration set event destination.A fluent builder forConfigurationSetEventDestination
.Options for a configuration set event destination.A builder forConfigurationSetEventDestinationOptions
An implementation forConfigurationSetEventDestinationOptions
Properties for a configuration set event destination.A builder forConfigurationSetEventDestinationProps
An implementation forConfigurationSetEventDestinationProps
Properties for a configuration set.A builder forConfigurationSetProps
An implementation forConfigurationSetProps
TLS policy for a configuration set.A dedicated IP pool.A fluent builder forDedicatedIpPool
.Properties for a dedicated IP pool.A builder forDedicatedIpPoolProps
An implementation forDedicatedIpPoolProps
The identity to use for DKIM.Configuration for DKIM identity.A builder forDkimIdentityConfig
An implementation forDkimIdentityConfig
A DKIM record.A builder forDkimRecord
An implementation forDkimRecord
A rule added at the top of the rule set to drop spam/virus.A fluent builder forDropSpamReceiptRule
.Example:A builder forDropSpamReceiptRuleProps
An implementation forDropSpamReceiptRuleProps
The signing key length for Easy DKIM.An email identity.A fluent builder forEmailIdentity
.Properties for an email identity.A builder forEmailIdentityProps
An implementation forEmailIdentityProps
Email sending event.An event destination.A configuration set.Internal default implementation forIConfigurationSet
.A proxy class which represents a concrete javascript instance of this type.A configuration set event destination.Internal default implementation forIConfigurationSetEventDestination
.A proxy class which represents a concrete javascript instance of this type.A dedicated IP pool.Internal default implementation forIDedicatedIpPool
.A proxy class which represents a concrete javascript instance of this type.Identity.An email identity.Internal default implementation forIEmailIdentity
.A proxy class which represents a concrete javascript instance of this type.A receipt rule.Internal default implementation forIReceiptRule
.A proxy class which represents a concrete javascript instance of this type.An abstract action for a receipt rule.Internal default implementation forIReceiptRuleAction
.A proxy class which represents a concrete javascript instance of this type.A receipt rule set.Internal default implementation forIReceiptRuleSet
.A proxy class which represents a concrete javascript instance of this type.Virtual Deliverablity Manager (VDM) attributes.Internal default implementation forIVdmAttributes
.A proxy class which represents a concrete javascript instance of this type.LambdaAction configuration.A builder forLambdaActionConfig
An implementation forLambdaActionConfig
The action to take if the required MX record for the MAIL FROM domain isn't found.A receipt filter.A fluent builder forReceiptFilter
.The policy for the receipt filter.Construction properties for a ReceiptFilter.A builder forReceiptFilterProps
An implementation forReceiptFilterProps
A new receipt rule.A fluent builder forReceiptRule
.Properties for a receipt rule action.A builder forReceiptRuleActionConfig
An implementation forReceiptRuleActionConfig
Options to add a receipt rule to a receipt rule set.A builder forReceiptRuleOptions
An implementation forReceiptRuleOptions
Construction properties for a ReceiptRule.A builder forReceiptRuleProps
An implementation forReceiptRuleProps
A new receipt rule set.A fluent builder forReceiptRuleSet
.Construction properties for a ReceiptRuleSet.A builder forReceiptRuleSetProps
An implementation forReceiptRuleSetProps
S3Action configuration.A builder forS3ActionConfig
An implementation forS3ActionConfig
Scaling mode to use for this IP pool.SNSAction configuration.A builder forSNSActionConfig
An implementation forSNSActionConfig
StopAction configuration.A builder forStopActionConfig
An implementation forStopActionConfig
Reasons for which recipient email addresses should be automatically added to your account's suppression list.The type of TLS policy for a receipt rule.Virtual Deliverablity Manager (VDM) attributes.A fluent builder forVdmAttributes
.Properties for the Virtual Deliverablity Manager (VDM) attributes.A builder forVdmAttributesProps
An implementation forVdmAttributesProps
WorkmailAction configuration.A builder forWorkmailActionConfig
An implementation forWorkmailActionConfig