Cool Solutions

Script for testing SMTP with Telnet

Laura Buckley


January 2, 2018 9:17 am





There are times when we, as email system administrators, may have issues with mail flow between our GWIAs and external systems. A common troubleshooting step is to go back to basics and use Telnet to test the SMTP connectivity and send a test email. This troubleshooting step can prove invaluable and assist us in diagnosing where the problem is. To make my life a little easier I wrote a script which [almost] automates this task for me, negating the need to remember the exact commands and syntax. I have found this useful and thought I’d share here.

Disclaimer:  This was created out of my own necessity.  Scripting does not come naturally to me, so this won’t look pretty.

On your GWIA server, in an appropriate directory, create a file. I call it

Copy this code into the file:


read -p "Enter Recipient's Mail Server: " server
read -p "Enter SMTP Port: " port
read -p "Enter Your Email Address: " from
read -p "Enter Recipient's Email Address: " to

# create message
function mail_input {
echo "ehlo $(hostname -f)"
echo "MAIL FROM: <$from>"
echo "RCPT TO: <$to>"
echo "DATA"
echo "From: <$from>"
echo "To: <$to>"
echo "Subject: Testing SMTP Mail"
echo "This is only a test. Please do not panic. If this works, then all is well, else all is not well."
echo "."
echo "quit"

mail_input | netcat $server $port || err_exit 

Save the file and mark it executable

 chmod +x 

Edit the subject line and text to be sent in the email to suit your needs. When you run the script it will prompt you for the necessary information to complete the task at hand.


2 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 52 votes, average: 5.00 out of 5 (2 votes, average: 5.00 out of 5)
You need to be a registered member to rate this post.

Tags: , ,
Categories: Collaboration, GroupWise, Messaging & Team Collaboration, Technical


Disclaimer: This content is not supported by Micro Focus. It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test it thoroughly before using it in a production environment.