As a cheap hack workaround on a number of servers that don't have the mail
command, a script was written that echoes SMTP commands into a telnet session. The relevant part of the script looks like
telnet mailserver 25 << EOF
EHLO $HOST
MAIL FROM: root@$HOST
(and so on)
EOF
This intermittently fails, with a "connection closed by remote host". A tcpdump
of a failing session confirms that the Postfix mail server is closing the connection immediately after sending the 220
welcome message. That is, none of the input redirection has made it over the wire.
So far, I haven't been able to pin down the conditions of the failure, but I can confirm that using nc
(netcat) works flawlessly, every time.
A number of questions on this site and Stack Overflow are adamant that nc
is the right tool for this job. I am interested in why this is the case.
- Why is the failure intermittent?
- Why does the mail server hang up before a single line of input from the redirected is sent over the wire?
- Why does
telnet
break butnetcat
not?