Requirement
$ sudo yum install mailx
$ sudo apt-get install mailutils
#!/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." |
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND