Created
October 21, 2019 21:34
-
-
Save wr0ngway/7b6f3334601139bb9f7a0b04d324b4a2 to your computer and use it in GitHub Desktop.
For testing that AWS SES is configured correctly and can send emails
This file contains hidden or 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
#!/usr/bin/env bash | |
# fail fast | |
set -e | |
server=email-smtp.us-east-1.amazonaws.com:587 | |
config_set=default | |
subject="Amazon SES SMTP Test" | |
message="This message was sent using the Amazon SES SMTP interface." | |
function usage { | |
echo "usage: $(basename $0) [options] -u user -p pass -f from@email -t to@email" | |
echo | |
echo " Options:" | |
echo | |
echo " -u smtp_user The smtp login username (smtp aws access key id)" | |
echo " -p smtp_pass The smtp login password (smtp aws secret access key)" | |
echo " -f from_email The email sending from" | |
echo " -t to_email The email sending to" | |
echo " -s server The smtp endpoiint to send mail through" | |
echo " (default: $server)" | |
echo " -d domain The sending domain (default: domain from from_email)" | |
echo " -c config_set The SES configuration set to use (default: $config_set)" | |
echo " -b subject The email subject (default: $subject)" | |
echo " -m message The email message" | |
echo " (default: $message)" | |
echo | |
exit 1 | |
} | |
while getopts ":u:p:f:t:s:d:c:b:m:" opt; do | |
case $opt in | |
u) | |
user="$OPTARG" | |
;; | |
p) | |
pass="$OPTARG" | |
;; | |
f) | |
from_email="$OPTARG" | |
;; | |
t) | |
to_email="$OPTARG" | |
;; | |
s) | |
server="$OPTARG" | |
;; | |
d) | |
sending_domain="$OPTARG" | |
;; | |
c) | |
config_set="$OPTARG" | |
;; | |
b) | |
subject="$OPTARG" | |
;; | |
m) | |
message="$OPTARG" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [[ -z $user || -z $pass || -z $from_email || -z $to_email ]]; | |
then | |
usage | |
fi | |
sending_domain=${sending_domain:-${from_email##*@}} | |
smtp_user=$(echo -n "$user" | openssl enc -base64) | |
smtp_pass=$(echo -n "$pass" | openssl enc -base64) | |
#echo "Testing connection" | |
#openssl s_client -crlf -quiet -starttls smtp -connect $server | |
body="\ | |
EHLO $sending_domain | |
AUTH LOGIN | |
$smtp_user | |
$smtp_pass | |
MAIL FROM: $from_email | |
RCPT TO: $to_email | |
DATA | |
X-SES-CONFIGURATION-SET: $config_set | |
From: $from_email | |
To: $to_email | |
Subject: $subject | |
$message | |
. | |
QUIT | |
" | |
echo "Sending email" | |
echo "$body" | |
echo "$body" | openssl s_client -crlf -quiet -starttls smtp -connect $server |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment