Skip to content

Instantly share code, notes, and snippets.

@omar-yassin
Created August 26, 2015 18:52
Show Gist options
  • Save omar-yassin/223f7904e27738e3b2e3 to your computer and use it in GitHub Desktop.
Save omar-yassin/223f7904e27738e3b2e3 to your computer and use it in GitHub Desktop.
AWS CLI SES send-email
# email using aws ses
function send-email ()
{
email_message="/tmp/email_message"
email_cleanup="/tmp/email_cleanup"
email_destination="/tmp/email_destination"
# we need to clean up our logs so we can send via json; remove new line and quotes
# and I don't understand the bash issue with running cat | sed in the $email_message declaration. Fun TODO to understand why?
cat $LOG_FILE | sed ':a;N;$!ba;s/\n/\\n/g' | tr -d '"' > $email_cleanup
cat > $email_message <<EOF
{
"Subject": {
"Data": "$message",
"Charset": "UTF-8"
},
"Body": {
"Text": {
"Data": "`cat $email_cleanup`",
"Charset": "UTF-8"
}
}
}
EOF
cat > $email_destination <<EOF
{
"ToAddresses": ["$email_addr"],
"CcAddresses": [],
"BccAddresses": []
}
EOF
$AWS_BIN ses send-email --from "$from_addr" --destination file://$email_destination --message file://$email_message --region us-east-1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment