Envie e-mails via Amazon SES com Bash e cURL

Script de shell simples para enviar e-mails via Amazon SES.

Para funcionar corretamente, ajuste as variáveis de ambiente Bash TO, FROM, SUBJECTe MESSAGE.

Além disso, as variáveis ​​de ambiente AWS_SECRET_KEYe AWS_ACCESS_KEYdevem ser definidas corretamente.

#!/bin/bash

TO
="Email To <to@example.com>"
FROM
="Email From <from@example.com>"
SUBJECT
="<YOUR SUBJECT HERE>"
MESSAGE
="<YOUR MESSAGE HERE>"

date
="$(date -R)"
priv_key
="$AWS_SECRET_KEY"
access_key
="$AWS_ACCESS_KEY"
signature
="$(echo -n "$date" | openssl dgst -sha256 -hmac "$priv_key" -binary | base64 -w 0)"
auth_header
="X-Amzn-Authorization: AWS3-HTTPS AWSAccessKeyId=$access_key, Algorithm=HmacSHA256, Signature=$signature"
endpoint
="https://email.us-east-1.amazonaws.com/"

action
="Action=SendEmail"
source
="Source=$FROM"
to
="Destination.ToAddresses.member.1=$TO"
subject
="Message.Subject.Data=$SUBJECT"
message
="Message.Body.Text.Data=$MESSAGE"

curl
-v -X POST -H "Date: $date" -H "$auth_header" --data-urlencode "$message" --data-urlencode "$to" --data-urlencode "$source" --data-urlencode "$action" --data-urlencode "$subject" "$endpoint"