AWS Simple Email Service (SES)
Since Camel 3.1
Only producer is supported
The AWS2 SES component supports sending emails with Amazon’s SES service.
Prerequisites
You must have a valid Amazon Web Services developer account, and be signed up to use Amazon SES. More information is available at Amazon SES.
URI Format
aws2-ses://from[?options]
You can append query options to the URI in the following format:
?options=value&option2=value&…
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The AWS Simple Email Service (SES) component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The email addresses of the Bcc (blind carbon copy) recipients, as a comma-separated list. The CamelAwsSesBcc header replaces this option. For a raw mail, see the to option. | String | ||
The email addresses of the Cc (carbon copy) recipients, as a comma-separated list. The CamelAwsSesCc header replaces this option. For a raw mail, see the to option. | String | ||
The configuration that the endpoints of this component start from. Each endpoint gets a copy of it, and the options of the endpoint replace its values. | Ses2Configuration | ||
The name of the configuration set of Amazon SES to send the mail with, for example to publish its sending events. The CamelAwsSesConfigurationSet header replaces this option. It is used for a raw mail too. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The AWS region of Amazon SES, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. The sender identity must be verified in this region. Enum values:
| String | ||
The reply-to email addresses of the mail, as a comma-separated list. The CamelAwsSesReplyToAddresses header replaces this option. It is not used for a raw mail. | String | ||
The email address that Amazon SES forwards bounces and complaints to when email feedback forwarding is enabled. The address itself or its domain must be verified in Amazon SES. The CamelAwsSesReturnPath header replaces this option. It is not used for a raw mail. | String | ||
The subject of the mail. The CamelAwsSesSubject header replaces this option. Amazon SES requires a subject, unless the body is a raw mail, which has its own subject and does not use this option. | String | ||
The email addresses of the To recipients, as a comma-separated list. The CamelAwsSesTo header replaces this option. For a raw mail, the addresses of the to, cc and bcc options are the recipients that Amazon SES sends the mail to, and the To, Cc and Bcc headers of the mail stay as they are. When none is set, Amazon SES sends a raw mail to the recipients in its To, Cc and Bcc headers. | String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
Autowired To use a custom software.amazon.awssdk.services.ses.SesClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | SesClient | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Used for enabling or disabling all consumer based health checks from this component. | true | boolean | |
Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true. | true | boolean | |
The host name of the proxy that the HTTP client of Amazon SES connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon SES connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon SES uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonSESClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonSESClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the HTTP client of Amazon SES trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Endpoint Options
The AWS Simple Email Service (SES) endpoint is configured using URI syntax:
aws2-ses:from
With the following path and query parameters:
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The email addresses of the Bcc (blind carbon copy) recipients, as a comma-separated list. The CamelAwsSesBcc header replaces this option. For a raw mail, see the to option. | String | ||
The email addresses of the Cc (carbon copy) recipients, as a comma-separated list. The CamelAwsSesCc header replaces this option. For a raw mail, see the to option. | String | ||
The name of the configuration set of Amazon SES to send the mail with, for example to publish its sending events. The CamelAwsSesConfigurationSet header replaces this option. It is used for a raw mail too. | String | ||
Whether to send the requests to the URI of the uriEndpointOverride option instead of the endpoint of the region. It has no effect when uriEndpointOverride is not set. | false | boolean | |
The AWS region of Amazon SES, as a region ID such as eu-west-1, which is the value of Region.EU_WEST_1.id(). If not set, the default region provider chain of the AWS SDK is used. The sender identity must be verified in this region. Enum values:
| String | ||
The reply-to email addresses of the mail, as a comma-separated list. The CamelAwsSesReplyToAddresses header replaces this option. It is not used for a raw mail. | String | ||
The email address that Amazon SES forwards bounces and complaints to when email feedback forwarding is enabled. The address itself or its domain must be verified in Amazon SES. The CamelAwsSesReturnPath header replaces this option. It is not used for a raw mail. | String | ||
The subject of the mail. The CamelAwsSesSubject header replaces this option. Amazon SES requires a subject, unless the body is a raw mail, which has its own subject and does not use this option. | String | ||
The email addresses of the To recipients, as a comma-separated list. The CamelAwsSesTo header replaces this option. For a raw mail, the addresses of the to, cc and bcc options are the recipients that Amazon SES sends the mail to, and the To, Cc and Bcc headers of the mail stay as they are. When none is set, Amazon SES sends a raw mail to the recipients in its To, Cc and Bcc headers. | String | ||
The URI of the endpoint to use instead of the endpoint of the region, for example http://localhost:4566 for a local emulator. It is used only when overrideEndpoint is true. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired To use a custom software.amazon.awssdk.services.ses.SesClient, which is autowired when the registry has a single one. When this option is set, the credentials, region, proxy, endpoint override and trustAllCertificates options are not used. The endpoint does not close a client that is set or autowired. | SesClient | ||
The host name of the proxy that the HTTP client of Amazon SES connects through. The proxy is used only when the proxyPort option is set too. | String | ||
The port of the proxy that the HTTP client of Amazon SES connects through. The proxy is used only when the proxyHost option is set too. | Integer | ||
The protocol that the HTTP client of Amazon SES uses to connect to the proxy. It is used only when the proxyHost and proxyPort options are set. Enum values:
| HTTPS | Protocol | |
The access key ID of the AWS credentials, used together with the secretKey option. The endpoint requires it, unless amazonSESClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The name of the profile in the AWS shared credentials and config files, used when useProfileCredentialsProvider is true. If not set, the AWS SDK uses its default profile, which the AWS_PROFILE environment variable can change. | String | ||
The secret access key of the AWS credentials, used together with the accessKey option. The endpoint requires it, unless amazonSESClient is set or useDefaultCredentialsProvider or useProfileCredentialsProvider is true. It is also required when useSessionCredentials is true. | String | ||
The session token of temporary AWS credentials, for example of an assumed IAM role. It is used only when useSessionCredentials is true, together with the accessKey and secretKey options. All three are then required: if one of the three is missing, creating the client fails. | String | ||
Whether the HTTP client of Amazon SES trusts every TLS certificate without checking it. It applies to any endpoint, not only to an overridden one, so use it only for testing, for example against a local emulator. | false | boolean | |
Whether to load the credentials with the default credentials provider chain of the AWS SDK, which looks in system properties, environment variables, the shared credentials and config files, and the container or instance role. It takes precedence over the other credentials options. | false | boolean | |
Whether to load the credentials from a profile of the AWS shared credentials and config files, the one of the profileCredentialsName option. It is not used when useDefaultCredentialsProvider is true, and it takes precedence over the session and static credentials. | false | boolean | |
Whether to use temporary credentials made of the accessKey, secretKey and sessionToken options, for example those of an assumed IAM role. It is not used when useDefaultCredentialsProvider or useProfileCredentialsProvider is true. | false | boolean |
Message Headers
The AWS Simple Email Service (SES) component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The email address of the sender. It replaces the from of the endpoint. | String | |
CamelAwsSesMessageId (producer) Constant: | The ID of the mail that Amazon SES returns, which the producer sets after sending the mail. | String | |
CamelAwsSesReplyToAddresses (producer) Constant: | The reply-to email addresses of the mail, as a comma-separated list. It replaces the replyToAddresses option. It is not used for a raw mail. | String | |
CamelAwsSesReturnPath (producer) Constant: | The email address that Amazon SES forwards bounces and complaints to when email feedback forwarding is enabled. It replaces the returnPath option. It is not used for a raw mail. | String | |
| Constant: | The subject of the mail. It replaces the subject option. It is not used for a raw mail. | String | |
| Constant: | The email addresses of the To recipients, as a comma-separated list. It replaces the to option. | String | |
| Constant: | The email addresses of the Cc (carbon copy) recipients, as a comma-separated list. It replaces the cc option. | String | |
| Constant: | The email addresses of the Bcc (blind carbon copy) recipients, as a comma-separated list. It replaces the bcc option. | String | |
| Constant: | The message tags of the mail, as a Map of tag name to tag value. Amazon SES includes them in the sending events that a configuration set publishes. It is used for a raw mail too. | Map | |
CamelAwsSesHtmlEmail (producer) Constant: | Whether the body is the HTML of the mail instead of its plain text, which it is when the header is not set. It is not used for a raw mail. | Boolean | |
CamelAwsSesConfigurationSet (producer) Constant: | The name of the configuration set of Amazon SES to send the mail with. It replaces the configurationSet option. | String |
Message Body
The message body at each side of the AWS Simple Email Service (SES) component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| The text of the mail, or its HTML with the CamelAwsSesHtmlEmail header set to true: bytes, a stream or a file are read as text, and a Map or a POJO is sent as its toString(), so marshal it first. A jakarta.mail Message or a RawMessage is sent as a raw mail as it is, a SendRawEmailRequest is sent as the request, and no body fails. |
Producer output |
| Unchanged, with the id of the mail in the CamelAwsSesMessageId header. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Required SES component options
You have to provide the amazonSESClient in the Registry or your accessKey and secretKey to access the Amazon’s SES.
Usage
Static credentials, Default Credential Provider and Profile Credentials Provider
You have the possibility of avoiding the usage of explicit static credentials by specifying the useDefaultCredentialsProvider option and set it to true.
The order of evaluation for Default Credentials Provider is the following:
-
Java system properties -
aws.accessKeyIdandaws.secretKey. -
Environment variables -
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. -
Web Identity Token from AWS STS.
-
The shared credentials and config files.
-
Amazon ECS container credentials - loaded from the Amazon ECS if the environment variable
AWS_CONTAINER_CREDENTIALS_RELATIVE_URIis set. -
Amazon EC2 Instance profile credentials.
You have also the possibility of using Profile Credentials Provider, by specifying the useProfileCredentialsProvider option to true and profileCredentialsName to the profile name.
Only one of static, default and profile credentials could be used at the same time.
For more information about this you can look at AWS credentials documentation
Advanced SesClient configuration
If you need more control over the SesClient instance configuration you can create your own instance and refer to it from the URI:
-
Java
-
XML
-
YAML
from("direct:start")
.to("aws2-ses://example@example.com?amazonSESClient=#client"); <route>
<from uri="direct:start"/>
<to uri="aws2-ses://example@example.com?amazonSESClient=#client"/>
</route> - route:
from:
uri: direct:start
steps:
- to:
uri: aws2-ses://example@example.com
parameters:
amazonSESClient: "#client" The #client refers to a SesClient in the Registry.
Message body
The producer sends the message body as follows:
| Body | Sent as |
|---|---|
text (a | a plain mail ( |
| a raw mail ( |
| a raw mail ( |
| the request as it is ( |
For a raw mail (a jakarta.mail.Message or RawMessage body), the source is the from option or the CamelAwsSesFrom header, and the destinations are the addresses of the to, cc and bcc options or the CamelAwsSesTo, CamelAwsSesCc and CamelAwsSesBcc headers. When none of them is set, SES sends the mail to the recipients of the To, Cc and Bcc headers of the raw mail. The subject is the one of the raw mail.
A message without a body fails with an InvalidPayloadException, and nothing is sent to SES.
The to, cc, bcc and replyToAddresses options and their headers are a String; give several addresses as a comma-separated list, such as to1@example.com,to2@example.com.
Examples
Producer Examples
-
Java
-
XML
-
YAML
from("direct:start")
.setHeader(Ses2Constants.SUBJECT, constant("This is my subject"))
.setHeader(Ses2Constants.TO, constant("to@example.com"))
.setBody(constant("This is my message text."))
.to("aws2-ses://from@example.com?accessKey=xxx&secretKey=yyy"); <route>
<from uri="direct:start"/>
<setHeader name="CamelAwsSesSubject">
<constant>This is my subject</constant>
</setHeader>
<setHeader name="CamelAwsSesTo">
<constant>to@example.com</constant>
</setHeader>
<setBody>
<constant>This is my message text.</constant>
</setBody>
<to uri="aws2-ses://from@example.com?accessKey=xxx&secretKey=yyy"/>
</route> - route:
from:
uri: direct:start
steps:
- setHeader:
name: CamelAwsSesSubject
constant: "This is my subject"
- setHeader:
name: CamelAwsSesTo
constant: "to@example.com"
- setBody:
constant: "This is my message text."
- to:
uri: aws2-ses://from@example.com
parameters:
accessKey: xxx
secretKey: yyy Dependencies
Maven users will need to add the following dependency to their pom.xml.
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-aws2-ses</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.