Mailscript with netcat: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Thomas (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „#!/bin/bash # script to send test mail with netcat. # expects the following arguments: # 1. recepient mail server # 2. port (typically 25 or 465) # 3. mail fr…“) |
Thomas (Diskussion | Beiträge) |
||
| Zeile 1: | Zeile 1: | ||
| + | <pre> | ||
#!/bin/bash | #!/bin/bash | ||
# script to send test mail with netcat. | # script to send test mail with netcat. | ||
| Zeile 45: | Zeile 46: | ||
# send | # send | ||
mail_input | nc $1 $2 || err_exit | mail_input | nc $1 $2 || err_exit | ||
| + | </pre> | ||
Version vom 11. September 2014, 15:14 Uhr
#!/bin/bash
# script to send test mail with netcat.
# expects the following arguments:
# 1. recepient mail server
# 2. port (typically 25 or 465)
# 3. mail from (e.g. from@example.com)
# 4. mail to (e.g. to@example.com)
# for mail_input function
from=$3
to=$4
# error handling
function err_exit { echo -e 1>&2; exit 1; }
# check if proper arguments are supplied
if [ $# -ne 4 ]; then
echo -e "\n Usage error!"
echo " This script requires four arguments:"
echo " 1. recepient mail server"
echo " 2. port (typically 25 or 465)"
echo " 3. mail from (e.g. from@example.com)"
echo " 4. mail to (e.g. to@example.com)"
exit 1
fi
# 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 one two three"
echo "This is only a test. Please do not panic. If this works, then all is well, else all is not well."
echo "In closing, Lorem ipsum dolor sit amet, consectetur adipiscing elit."
echo "."
echo "quit"
}
# test
#mail_input
# send
mail_input | nc $1 $2 || err_exit