Skip to content

Instantly share code, notes, and snippets.

@devops-school
Last active April 3, 2024 16:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devops-school/9ec9fb184dda51eaff921e87d258b8f5 to your computer and use it in GitHub Desktop.
Save devops-school/9ec9fb184dda51eaff921e87d258b8f5 to your computer and use it in GitHub Desktop.
Bash/Shell Script to test SMTP SES Credentials
#!/bin/bash
# Set the SMTP server name and port number
SMTP_SERVER="email-smtp.ap-south-1.amazonaws.com"
SMTP_PORT="587"
# Set the sender email address and AWS SES username and password
SENDER_EMAIL="contact@XXXXXXXX.com"
SES_USERNAME="XXXXXXXXXXX"
SES_PASSWORD="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Set the recipient email address
RECIPIENT_EMAIL="XXXXXX@XXXXXXXX.com"
# Test SMTP credentials using openssl and telnet
echo "Testing SMTP credentials..."
openssl s_client -connect $SMTP_SERVER:$SMTP_PORT -starttls smtp -crlf <<< "EHLO $SMTP_SERVER" > /dev/null
echo "HELO $SMTP_SERVER" | openssl s_client -starttls smtp -connect $SMTP_SERVER:$SMTP_PORT -crlf -quiet -ign_eof 2>&1 > /dev/null
echo "QUIT" | openssl s_client -starttls smtp -connect $SMTP_SERVER:$SMTP_PORT -crlf -quiet -ign_eof 2>&1 > /dev/null
# Send a test email using telnet
echo "Sending a test email..."
{
sleep 1
echo "EHLO $SMTP_SERVER"
sleep 1
echo "AUTH LOGIN"
sleep 1
echo -n "$SES_USERNAME" | base64
sleep 1
echo -n "$SES_PASSWORD" | base64
sleep 1
echo "MAIL FROM: <$SENDER_EMAIL>"
sleep 1
echo "RCPT TO: <$RECIPIENT_EMAIL>"
sleep 1
echo "DATA"
sleep 1
echo "Subject: Test Email"
echo "From: $SENDER_EMAIL"
echo "To: $RECIPIENT_EMAIL"
echo "This is a test email."
echo "."
sleep 1
echo "QUIT"
} | openssl s_client -starttls smtp -connect $SMTP_SERVER:$SMTP_PORT -crlf -quiet -ign_eof 2>&1 > /dev/null
echo "Test complete."
#!/bin/bash
# Set the SMTP server name and port number
SMTP_SERVER="email-smtp.us-east-1.amazonaws.com"
SMTP_PORT="587"
# Set the sender email address and AWS SES username and password
SENDER_EMAIL="your-sender-email@example.com"
SES_USERNAME="AWS-SES-USERNAME"
SES_PASSWORD="AWS-SES-PASSWORD"
# Set the recipient email address
RECIPIENT_EMAIL="recipient-email@example.com"
# Test SMTP credentials using openssl and mailx
echo "Testing SMTP credentials..."
openssl s_client -connect $SMTP_SERVER:$SMTP_PORT -starttls smtp -crlf <<< "EHLO $SMTP_SERVER" > /dev/null
echo "HELO $SMTP_SERVER" | openssl s_client -starttls smtp -connect $SMTP_SERVER:$SMTP_PORT -crlf -quiet -ign_eof 2>&1 > /dev/null
# Send a test email using mailx
echo "Sending a test email..."
echo "This is a test email" | mailx -v -r $SENDER_EMAIL -s "Test Email" -S smtp="$SMTP_SERVER:$SMTP_PORT" -S smtp-use-starttls -S smtp-auth=login -S smtp-auth-user="$SES_USERNAME" -S smtp-auth-password="$SES_PASSWORD" $RECIPIENT_EMAIL
echo "Test complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment