Skip to content

Instantly share code, notes, and snippets.

@gilgamez
Created June 7, 2013 07:33
Show Gist options
  • Save gilgamez/5727600 to your computer and use it in GitHub Desktop.
Save gilgamez/5727600 to your computer and use it in GitHub Desktop.
sent smtp mail from the command line
#!/bin/bash
#### Command line parameters ####
HELO=`hostname`
MAILSERVER=${1:?Mailserver}
PORT=${2:?Mailserver Port}
MAILFROM=${3:?From}
MAILTO=${4:?To}
SUBJECT=${5:?Subject}
#### Message body from stdin ####
DATA=`unix2dos`
#### SEND MAIL via RAW TCP #######
echo
echo "Connecting to $MAILSERVER on Port $PORT";
echo "Please wait ... "
echo
exec 3<>/dev/tcp/$MAILSERVER/$PORT
if [ $? -ne 0 ] ; then
echo
echo "ERROR: Cannot connect to the Mail Server";
echo "Please check the servername and/or the port number"
exit
fi
echo -en "HELO ${HELO}\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" >&3
echo -en "\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