This example showcases how to use the AWS SES client with Quarkus. Despite the fact that this example uses local AWS SES for integration test purposes, we encourage you to use SES from an AWS account as it allows you to send emails. Local instance of SES only mocks service APIs and doesn't send any emails.
- Run
./mvnw clean quarkus:dev
Using sync endpoint
curl -XPOST -H"Content-type: application/json" http://localhost:8080/sync/email -d'{"from": "from-quarkus@example.com", "to": "to-quarkus@example.com", "subject": "Hello from Quarkus", "body": "Quarkus is awesome"}'Or async endpoint
curl -XPOST -H"Content-type: application/json" http://localhost:8080/async/email -d'{"from": "from-quarkus@example.com", "to": "to-quarkus@example.com", "subject": "Hello from Quarkus", "body": "Quarkus is awesome"}'As a result, you will see the ID of the message as SES returned. E.g.:
010701724bec5607-e34882d5-a8ce-4f2b-a837-da75989e43c0-000000
As a prerequisite, install the AWS Command Line Interface.
Start LocalStack:
docker run \
--rm \
--name local-ses \
-p 4566:4566 \
localstack/localstackSES listens on localhost:4566 for REST endpoints.
Create an AWS profile for your local instance using AWS CLI:
aws configure --profile localstackAWS Access Key ID [None]: test-key
AWS Secret Access Key [None]: test-secret
Default region name [None]: us-east-1
Default output format [None]:
Verify the email addresses you're going to use when running the application.
aws ses verify-email-identity --email-address from-quarkus@example.com --profile localstack --endpoint-url=http://localhost:4566You can compile the application and run it with:
./mvnw install
AWS_PROFILE=localstack java -Dquarkus.ses.endpoint-override=http://localhost:4566 -jar ./target/quarkus-app/quarkus-run.jarYou can now replay the curl commands above.
You can compile the application into a native executable using:
./mvnw install -DnativeAnd run it with:
AWS_PROFILE=localstack ./target/amazon-ses-quickstart-1.0.0-SNAPSHOT-runner -Dquarkus.ses.endpoint-override=http://localhost:4566Build a native image in a container by running:
./mvnw install -Dnative -DskipTests -Dquarkus.native.container-build=trueBuild a Docker image:
docker build -f src/main/docker/Dockerfile.native -t quarkus/amazon-ses-quickstart .Create a network that connects your container with LocalStack:
docker network create localstackStop your LocalStack container you started at the beginning:
docker stop local-sesStart LocalStack and connect to the network:
docker run \
--rm \
--name local-ses \
--network=localstack \
-p 4566:4566 \
localstack/localstackVerify the email addresses:
aws ses verify-email-identity --email-address from-quarkus@example.com --profile localstack --endpoint-url=http://localhost:4566Run the Quickstart container connected to that network (note that we're using the internal port of the LocalStack container):
docker run -i --rm --network=localstack \
-p 8080:8080 \
-e QUARKUS_SES_ENDPOINT_OVERRIDE="http://local-ses:4566" \
-e QUARKUS_SES_AWS_REGION="us-east-1" \
-e QUARKUS_SES_AWS_CREDENTIALS_TYPE="static" \
-e QUARKUS_SES_AWS_CREDENTIALS_STATIC_PROVIDER_ACCESS_KEY_ID="test-key" \
-e QUARKUS_SES_AWS_CREDENTIALS_STATIC_PROVIDER_SECRET_ACCESS_KEY="test-secret" \
quarkus/amazon-ses-quickstartReplay curl commands from above:
Clean up your environment:
docker stop local-ses
docker network rm localstackBefore you can use the AWS SDKs with SES, you must get an AWS access key ID and secret access key. For more information, see:
Verify the email addresses:
aws ses verify-email-identity --email-address from-quarkus@example.comOn AWS, verifying email identities or domain identities requires additional steps like changing DNS configuration or clicking verification links respectively. Use an email address that you can verify.
You can run the demo the same way as for a local instance, but you don't need to override the endpoint as you are going to communicate with the AWS service with the default AWS profile.
Run it:
java -jar ./target/quarkus-app/quarkus-run.jarOr, run it natively:
./target/amazon-ses-quickstart-1.0.0-SNAPSHOT-runner