Skip to content

aws

The aws output does up to three things for each email, in this order, each when its option is set:

  1. storage: store the email, or a part of it, in an Amazon S3 bucket;
  2. pubsub: send a CloudEvent describing the email to an Amazon SQS queue;
  3. ses: send the email with Amazon SES SendRawEmail.
  • An SMTP endpoint for applications that should send through SES without the SES API or SMTP credentials: the relay uses an IAM role. See replacing aws-smtp-relay.
  • Receive emails for your domain into S3 and process them from a queue, similar to SES receiving rules.

The output creates one AWS SDK client per service. Credentials and region come from the SDK default chain: environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION…), shared config files, or the role of the container or instance. s3client, sqsclient and sesClient pass options to each client, such as the region of the SES identity or an endpoint for a local emulator.

With "ses": true, the email is sent as received (with the server’s header changes) to the recipients the flow accepted (RCPT TO), blind copies included. SES needs the sender to be a verified identity, and the account to be out of the SES sandbox to send to any address.

sendRawEmailOptions adds parameters to the SendRawEmail call, such as a configuration set or the ARNs used to send through an identity of another account. They cannot change the message or the recipients.

storage.type selects what is stored:

type Stored object
raw (default) the whole email; with addRawHeaders (default true), X-smtp-relay-* headers are added at the top: RCPT_TO (one per recipient of the flow), MAIL_FROM, USER (if authenticated), CLIENT_HOSTNAME and HELO
attachments one object per attachment; put ${attachment} in path so they do not overwrite each other
text the text body, if any
html the HTML body, if any

storage.path is the object key and accepts the path variables. putOptions adds parameters to every PutObject call: storage class, encryption, ACL, metadata, tags.

pubsub.topic is the queue URL, for example https://sqs.us-east-1.amazonaws.com/123456789012/emails. The message body is the CloudEvent, in JSON. It does not contain the S3 object key: use a key the consumer can rebuild from the CloudEvent, such as ${iso8601}_${id} (from its time and data.server.id). sendMessageOptions adds parameters to the SendMessage call, such as the MessageGroupId a FIFO queue requires.

OptionTypeDescription
namestring

Name of the component, used in the logs and the output metrics, defaults to <type>_<position in the list>

pubsubobject

Send a CloudEvent describing the email to an Amazon SQS queue, after storage when both are set

pubsub.topicrequiredstring

URL of the Amazon SQS queue to send the message to, e.g. https://sqs.us-east-1.amazonaws.com/123456789012/my-queue

pubsub.truncatenumber
default 8192

Maximum length of the subject, text, html, attachment file names and client hostname in the CloudEvent, longer values are truncated

putOptionsobject

Extra parameters of the S3 PutObject calls of storage, for every storage.type

AWS SDK documentation

putOptions.ACLstring

Canned ACL of the object, e.g. private or bucket-owner-full-control

AWS SDK documentation

putOptions.ContentTypestring

MIME type of the object

AWS SDK documentation

putOptions.Metadataobject

User-defined metadata stored with the object

AWS SDK documentation

putOptions.SSEKMSKeyIdstring

KMS key to encrypt the object with when ServerSideEncryption is aws:kms

AWS SDK documentation

putOptions.ServerSideEncryptionstring

Server side encryption algorithm, e.g. AES256 or aws:kms

AWS SDK documentation

putOptions.StorageClassstring

Storage class of the object, e.g. STANDARD_IA

AWS SDK documentation

putOptions.Taggingstring

Tags of the object, URL query encoded, e.g. key1=value1&key2=value2

AWS SDK documentation

putOptions.…any

Any other option of the underlying SDK or library is accepted

s3clientobject

Options of the S3 client used by storage

See the AWS SDK documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-s3/Interface/S3ClientConfig/

AWS SDK documentation

s3client.credentialsobject

Static credentials, the SDK default credential chain is used when not set

AWS SDK documentation

s3client.endpointstring

URL of the service endpoint, to use instead of the default one of the region (e.g. a local emulator or a VPC endpoint)

AWS SDK documentation

s3client.maxAttemptsnumber

Maximum number of attempts for a request, retries included

AWS SDK documentation

s3client.regionstring

AWS region of the service, e.g. us-east-1

AWS SDK documentation

s3client.…any

Any other option of the underlying SDK or library is accepted

sendMessageOptionsobject

Extra parameters of the SQS SendMessage call of pubsub

AWS SDK documentation

sendMessageOptions.DelaySecondsnumber

Delay in seconds before the message becomes available, from 0 to 900

AWS SDK documentation

sendMessageOptions.MessageDeduplicationIdstring

Deduplication id of the message, for FIFO queues without content-based deduplication

AWS SDK documentation

sendMessageOptions.MessageGroupIdstring

Message group of the message, required by FIFO queues

AWS SDK documentation

sendMessageOptions.…any

Any other option of the underlying SDK or library is accepted

sendRawEmailOptionsobject

Extra parameters of the SES SendRawEmail call of ses

AWS SDK documentation

sendRawEmailOptions.ConfigurationSetNamestring

Configuration set to use when sending the email

AWS SDK documentation

sendRawEmailOptions.FromArnstring

ARN of the identity allowed to send for the From header address, for sending authorization

AWS SDK documentation

sendRawEmailOptions.ReturnPathArnstring

ARN of the identity allowed to send for the Return-Path address, for sending authorization

AWS SDK documentation

sendRawEmailOptions.Sourcestring

Sender address of the email, taken from the message when not set

AWS SDK documentation

sendRawEmailOptions.SourceArnstring

ARN of the identity allowed to send for the Source address, for sending authorization (e.g. an identity owned by another account)

AWS SDK documentation

sendRawEmailOptions.Tagsobject[]

Tags applied to the email, for event publishing

AWS SDK documentation

sendRawEmailOptions.…any

Any other option of the underlying SDK or library is accepted

sesboolean
default false

Send the raw email with Amazon SES SendRawEmail to the envelope recipients (RCPT TO), after storage and pubsub

sesClientobject

Options of the SES client used by ses, e.g. the region of the SES identity

See the AWS SDK documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-ses/Interface/SESClientConfig/

AWS SDK documentation

sesClient.credentialsobject

Static credentials, the SDK default credential chain is used when not set

AWS SDK documentation

sesClient.endpointstring

URL of the service endpoint, to use instead of the default one of the region (e.g. a local emulator or a VPC endpoint)

AWS SDK documentation

sesClient.maxAttemptsnumber

Maximum number of attempts for a request, retries included

AWS SDK documentation

sesClient.regionstring

AWS region of the service, e.g. us-east-1

AWS SDK documentation

sesClient.…any

Any other option of the underlying SDK or library is accepted

sqsclientobject

Options of the SQS client used by pubsub

See the AWS SDK documentation: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-sqs/Interface/SQSClientConfig/

AWS SDK documentation

sqsclient.credentialsobject

Static credentials, the SDK default credential chain is used when not set

AWS SDK documentation

sqsclient.endpointstring

URL of the service endpoint, to use instead of the default one of the region (e.g. a local emulator or a VPC endpoint)

AWS SDK documentation

sqsclient.maxAttemptsnumber

Maximum number of attempts for a request, retries included

AWS SDK documentation

sqsclient.regionstring

AWS region of the service, e.g. us-east-1

AWS SDK documentation

sqsclient.…any

Any other option of the underlying SDK or library is accepted

storageobject

Store the email, or a part of it, in an Amazon S3 bucket

storage.addRawHeadersboolean
default true

Prepend X-smtp-relay-* headers to a raw email before storing it: the envelope recipients (RCPT_TO), the envelope sender (MAIL_FROM), the authenticated user (USER), the client hostname (CLIENT_HOSTNAME) and the HELO name (HELO)

Only used when type is raw

storage.bucketrequiredstring

Name of the bucket to write to

storage.pathrequiredstring

Key of the object to write within the bucket

Variables written as ${name} are replaced: ${iso8601}, ${timestamp}, ${id}, ${messageId}, ${from}, ${subject}, ${to}, and ${attachment} (the attachment file name) when type is attachments. Use ${attachment} or ${id} to avoid overwriting objects

storage.type"raw" | "attachments" | "text" | "html"
default "raw"

Part of the email to save

raw: the whole email as received by our SMTP attachments: any files attached to the email, one object per attachment, ignoring emails without attachments text: The text content of the email if it exists html: The html content of the email if it exists

typerequired"aws"

Type of the component

Relay every email to SES, the setup of the former aws-smtp-relay:

configs/aws-smtp-relay.jsonc
// Replace my previous project aws-smtp-relay
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"localhost": {
"filters": [
// Allow any ip to use the SMTP
{
"type": "whitelist",
"ips": ["regexp:.*"]
}
],
"outputs": [
{
"type": "aws",
// Send it to SES
"ses": true
}
]
}
},
// Listen on every interface so the server is reachable from outside its container
"bind": "0.0.0.0",
"options": {
"disableReverseLookup": false,
"hideSTARTTLS": true,
// Do not require auth
"authOptional": true
}
}

Send through an SES identity owned by another AWS account, with sending authorization:

configs/aws-ses-cross-account.jsonc
// Sending Authorization setup can be found here: https://docs.aws.amazon.com/ses/latest/dg/sending-authorization.html
//
// This is useful if you have multiple SES identities in different accounts, regions or both that you want to re-use, or if you want to send e-mail using an identity that a 3rd party controls (customer, vendor, etc.).
//
// The account that owns the verified identity (e.g. 111111111111) attaches an identity policy allowing the account running the relay (e.g. 222222222222) to send:
// {
// "Version": "2012-10-17",
// "Statement": [{
// "Effect": "Allow",
// "Principal": { "AWS": "arn:aws:iam::222222222222:root" }, // This can be the account root or a more specific identity used by the AWS SDK. More information about available identities can be found here: https://docs.aws.amazon.com/sdkref/latest/guide/standardized-credentials.html
// "Action": ["ses:SendRawEmail"],
// "Resource": "arn:aws:ses:us-east-1:111111111111:identity/example.com"
// }]
// }
//
// The account running the relay (e.g. 222222222222) must have an IAM policy allowing it to send using the identity in the owning account (e.g. 111111111111):
// {
// "Version": "2012-10-17",
// "Statement": [{
// "Effect": "Allow",
// "Action": ["ses:SendRawEmail"],
// "Resource": "arn:aws:ses:us-east-1:111111111111:identity/example.com"
// }]
// }
//
// The relay then passes the identity ARN as SourceArn/FromArn/ReturnPathArn.
//
// IMPORTANT: The account running the relay MUST be removed from the sandbox in the same region that the SES identity exists in.
// In this case BOTH account 111111111111 and 222222222222 must be removed from the SES sandbox in us-east-1.
{
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json",
"flows": {
"cross-account-example": {
"filters": [
{
"type": "whitelist",
"from": ["regexp:.*@example.com"] // Recommended filter when multiple identities configured and need to be routed to different accounts
// This is a simple example and as-is creates an open relay, so additional filtering or authenticationis probably a good idea.
}
],
"outputs": [
{
"type": "aws",
"ses": true,
// Region of the SES identity in the owning account.
// Not required if it is the same region as the smtp-relay
"sesClient": {
"region": "us-east-1"
},
// ARN of the identity in the owning account
"sendRawEmailOptions": {
"SourceArn": "arn:aws:ses:us-east-1:111111111111:identity/example.com",
"FromArn": "arn:aws:ses:us-east-1:111111111111:identity/example.com",
"ReturnPathArn": "arn:aws:ses:us-east-1:111111111111:identity/example.com" // In testing this was not always necessary
}
}
]
}
},
// Listen on every interface so the server is reachable from outside its container
"bind": "0.0.0.0",
"options": {
"hideSTARTTLS": true,
"authOptional": true
}
}

Receive emails for a domain: store them in S3, then notify a queue:

mail2s3.yaml
$schema: https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json
flows:
inbound:
filters:
- type: whitelist
to: ["regexp:.*@mydomain.com"]
outputs:
- type: aws
storage:
bucket: mydomain-inbound
path: inbound/${iso8601}_${id}.eml
putOptions:
ServerSideEncryption: AES256
pubsub:
topic: https://sqs.eu-west-1.amazonaws.com/123456789012/inbound-emails
s3client:
region: eu-west-1
sqsclient:
region: eu-west-1
bind: 0.0.0.0
options:
authOptional: true