Skip to content

Instantly share code, notes, and snippets.

@jsidhu
Created March 20, 2017 20:43
Show Gist options
  • Save jsidhu/41cbfda16d487343a614ca0e271a660e to your computer and use it in GitHub Desktop.
Save jsidhu/41cbfda16d487343a614ca0e271a660e to your computer and use it in GitHub Desktop.
simple smtp test using bash /dev/tcp without telnet
D=$(date)
timeout 1 bash -c 'cat < /dev/null > /dev/tcp/smtp.mydomain.net/25'
port_25=$?
timeout 1 bash -c 'cat < /dev/null > /dev/tcp/smtp.mydomain.net/587'
port_587=$?
echo "$D Port Check result: port_25:$port_25 git:$port_587"
MAILSERVER=smtp.mydomain.net
PORT=25
[email protected]
MAILTO=$MAILFROM
SUBJECT="email test $MAILSERVER:$PORT"
DATA="this is a test email, please ignore. $D"
echo "Connecting to $MAILSERVER on Port $PORT";
exec 3<>/dev/tcp/$MAILSERVER/$PORT
if [ $? -ne 0 ] ; then
echo "ERROR: Cannot connect to the Mail Server";
exit
fi
echo -en "HELO aws.mydomain.net\r\n" >&3
echo -en "MAIL FROM:$MAILFROM\r\n" >&3
echo -en "RCPT TO:$MAILTO\r\n" >&3
echo -en "DATA\r\n" >&3
echo -en "Subject: $SUBJECT\r\n\r\n" >&3
echo -en "$DATA\r\n" >&3
echo -en ".\r\n" >&3
echo -en "QUIT\r\n" >&3
cat <&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment