Created
December 30, 2023 10:37
-
-
Save johnnydecimal/e7b1a03e26b79239363b5ddebef4f3c1 to your computer and use it in GitHub Desktop.
Amazon SES mail sending script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Replace these variables with your own values | |
# sender | |
# - Consider not using no-reply@, and instead use SES Inbound to receive replies | |
# - Consider a descriptive username@; some mobile clients will display it prominently, so it should make sense to the recipient. | |
# - Consider using a subdomain for bulk and transactional mail. Don't use the domain used by your users. | |
# - Consider using a verified domain identity. Don't use an email address identity within a domain that has a DMARC policy. | |
sender="hello@example.com" | |
subject="My great email" | |
body="This is the message. | |
It handles line breaks just fine. | |
But if you don\'t use ‘smart quotes’, you need to escape straight quotes. Because it\'s a bash script. | |
" | |
# replace with your region | |
region="ap-southeast-2" | |
# List of recipients, one per line. Defaults to SES mailbox simulator addresses (https://docs.aws.amazon.com/ses/latest/dg/send-an-email-from-console.html#send-email-simulator-how-to-use) | |
recipients=( | |
# "success+1@simulator.amazonses.com" | |
"recipient@example.com" | |
# I have an Airtable view that gives me a copy-pastable list of email addresses | |
# surrounded by double-quotes. | |
) | |
# Send an email to each recipient | |
# Iterate through the list of recipients. | |
# Invoke the AWS SES SendEmail operation with a single recipient defined in the Destination | |
for recipient in "${recipients[@]}"; do | |
echo sending to "$recipient" | |
aws sesv2 send-email \ | |
--from-email-address "$sender" \ | |
--destination "ToAddresses=$recipient" \ | |
--content "Simple={Subject={Data='$subject',Charset='UTF-8'},Body={Text={Data='$body',Charset='UTF-8'}}}" \ | |
--region "$region" | |
done | |
# The output will look similar to this, with a unique MessageID associated with each recipent. | |
# { | |
# "MessageId": "010001874edd1765-be4ea5c2-d2b1-4ffb-bfb9-46461d18d80c-000000" | |
# } | |
# ... 51 total message-ids | |
# { | |
# "MessageId": "010001874edd1b94-468ecee9-9198-4356-9f53-a108097777e5-000000" | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment