[memo] Sending email on aws cli via SES

Posted: May 18, 2021


AWS_REGION='us-east-1'
TO='example@example.com'
FROM='example@example.com'
SUBJECT='This is test subject'
TEXT='text part of the email'
HTML="<h1>Hi</h1><p>HTML part of email</p><a href='https://www.google.com'>Link to Google</a>"
CONFIGRATION_SET='my-configuration-set'

# send-email
aws --region "$AWS_REGION" ses send-email \
  --to "$TO" \
  --from "$FROM" \
  --subject "$SUBJECT" \
  --text "$TEXT" \
  --html "$HTML" \
  --configuration-set-name "$CONFIGRATION_SET" \
  --tags "Name=tag1,Value=value1"

# send-templated-email
TEMPLATE_NAME="example-template"
TEMPLATE_DATA='{"key": "value"}'

# (validate template and variables)
aws --region "$AWS_REGION" ses test-render-template \
  --template-name "$TEMPLATE_NAME" \
  --template-data "$TEMPLATE_DATA"

aws --region "$AWS_REGION" ses send-templated-email \
  --destination "ToAddresses=$TO" \
  --source "$FROM" \
  --template "$TEMPLATE_NAME" \
  --template-data "$TEMPLATE_DATA" \
  --configuration-set-name "$CONFIGRATION_SET" \
  --tags "Name=tag1,Value=value1"