Skip to content

Instantly share code, notes, and snippets.

@UnixSage
Created Sep 17, 2020
Embed
What would you like to do?
Send email via AWS SES from the command line
#!/bin/bash
DOMAIN="example.com"
MAILFROM="cmdline@${DOMAIN}"
MAILTO="someone@example.com"
SUBJECT="Amazon SES SMTP Test from ${HOSTNAME}"
USER="AWSKEY"
PASSWORD="AWSSMTPPASSWORD"
SMTPHOST="email-smtp.us-east-1.amazonaws.com:587"
EMAILFILE="/tmp/testemail.$$"
USER64=`echo -n ${USER} | openssl enc -base64`
PASSWORD64=`echo -n ${PASSWORD} | openssl enc -base64`
cat << EOT > ${EMAILFILE}
EHLO ${DOMAIN}
AUTH LOGIN
${USER64}
${PASSWORD64}
MAIL FROM: ${MAILFROM}
RCPT TO: ${MAILTO}
DATA
From: SESTEST <${MAILFROM}>
To: ${MAILTO}
Subject: ${SUBJECT}
This message was sent using the Amazon SES SMTP interface.
.
QUIT
EOT
openssl s_client -crlf -quiet -starttls smtp -connect ${SMTPHOST} < ${EMAILFILE}
rm ${EMAILFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment