E-posta göndermek için bir e-posta kimliği ve uygulamalarınızda kullanmak üzere örnek bir e-posta şablonu oluşturmak için aşağıdaki örneği kullanabilirsiniz.


Terraform'u çalıştırdıktan sonra AWS, e-posta kimliğinize e-posta adresini doğrulamak için bir bağlantıya tıklamanızı isteyen bir e-posta gönderecektir. Tıklamanız ve doğrulamayı onaylamanız gerekir. Bundan sonra, bu e-posta adresiyle e-posta göndermek için SES'i kullanabilirsiniz.


SES hizmetinizi etkinleştirdiğinizde AWS, hesabınızı Amazon SES sanal alanına yerleştirir. Bu nedenle, e-posta göndermeden önce hedef e-posta adreslerini de geçici olarak doğrulamanız gerekecektir. Normalde bunu production için asla yapmanıza gerek kalmayacak ama bu gönderide buna mecburuz.


Terraform kodu


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"
}

E-posta kimlik doğrulaması


// 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"
]
}