You can use example below to create an email identity to send emails from and example email template to use in your applications.


After running terraform, AWS will send an email to your email identity asking you to click a link to verify the email address. You need to click it and confirm verification. After that you can use SES for sending emails with this email address.


When you activate your SES service, AWS places your account in the Amazon SES sandbox. Because of this reason, you will have to temporarily verify destination email addresses as well before sending emails. Normally you will never need to do this in production but we have to in this post.


Terraform code


terraform {
required_version = "~> 1.4.4"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.30.0"
}
}
}

provider "aws" {
profile = "development"
region = "eu-west-1"
}

variable "noreply" {
description = "Noreply email address that is meant to be the verified identity."
type = string
sensitive = true
}

resource "aws_ses_email_identity" "noreply" {
email = var.noreply
}

resource "aws_ses_template" "api_credentials_text" {
name = "api-credentials-text"
subject = "API credentials for {{api}}!"
text = "Hello,\r\nID: {{id}}\nSecret: {{secret}}\r\nRegards"
}

Email identity verification


// This is the email identity we used above.
$ aws --profile development ses list-identities
{
"Identities": [
"noreply@example.com"
]
}

// Introduce receiver identity as well.
$ aws --profile development ses verify-email-identity --email-address receiver@example.com

// Finally this is what we have.
$ aws --profile development ses list-identities
{
"Identities": [
"noreply@example.com",
"receiver@example.com"
]
}