Skip to content

Instantly share code, notes, and snippets.

@ErikHarmon
Created May 5, 2016 22:06
Show Gist options
  • Save ErikHarmon/6da634b7bd302a3c75c59ad9664848b2 to your computer and use it in GitHub Desktop.
Save ErikHarmon/6da634b7bd302a3c75c59ad9664848b2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Easily test mail sending without anything but netcat.
# Instead of processing responses, it just slows down lines
# it sends and assumes it got a valid response.
FROM="$1"
TO="$2"
# Change these as appropriate.
EHLO="mail.example.com"
SERVER="example.com"
SUBJECT="Test Subject"
function delayit() {
IFS='\n'
while read i
do
echo "${i}"
sleep 1
done
}
function msg() {
delayit <<EOF
ehlo ${EHLO}
MAIL FROM: <${FROM}>
RCPT TO: <${TO}>
DATA
EOF
cat - <<EOF
From: <${FROM}>
To: <${TO}>
Subject: ${SUBJECT}
Dear User,
This is a test email.
End of message.
.
EOF
sleep 1
echo quit
}
msg | nc -v "${SERVER}" 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment