Last active
November 18, 2024 16:14
-
-
Save devops-school/9ec9fb184dda51eaff921e87d258b8f5 to your computer and use it in GitHub Desktop.
Bash/Shell Script to test SMTP SES Credentials
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 | |
# 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="[email protected]" | |
SES_USERNAME="XXXXXXXXXXX" | |
SES_PASSWORD="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
# Set the recipient email address | |
RECIPIENT_EMAIL="[email protected]" | |
# 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." |
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 | |
# 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="[email protected]" | |
SES_USERNAME="AWS-SES-USERNAME" | |
SES_PASSWORD="AWS-SES-PASSWORD" | |
# Set the recipient email address | |
RECIPIENT_EMAIL="[email protected]" | |
# 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