I wanna send an email via a command in Centos7. I used 'telnet' command for this issue like this:
I touch example.sh file and save these command inside it:
echo "open mail.test.com 25"
sleep 3
echo "mail from:sender@test.com"
echo "rcpt to:receiver@test.com"
echo "data"
echo "hello"
echo "."
sleep 3
And use this command ./example.sh | telnet
but it doesn't work.
telnet
is designed for interactive usage. Use netcat
, ncat
, nc
, socat
or any other tool of this family.
Example:
./example.sh | ncat mail.test.com 25
Herefore you have to edit your script:
echo "mail from:sender@test.com"
echo "rcpt to:receiver@test.com"
echo "data"
echo "hello"
echo "."
sleep 3
The last sleep 3
is important to give ncat
enough time to handle result.
btw, I have tested nothing (just written down)