在脚本中使用telnet命令发送邮件

时间:2019-05-18 11:07:24

标签: bash shell telnet

我想通过Centos7中的命令发送电子邮件。我使用'telnet'命令来解决此问题,例如:

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  

并使用此命令./example.sh | telnet
但这不起作用

能请你帮我吗 谢谢

1 个答案:

答案 0 :(得分:0)

telnet专为交互式使用而设计。使用netcatncatncsocat或该系列的任何其他工具。

示例:

./example.sh | ncat mail.test.com 25 

因此,您必须编辑脚本:

echo "mail from:sender@test.com"
echo "rcpt to:receiver@test.com"
echo "data"
echo "hello"
echo "."
sleep 3  

最后一个sleep 3对于给ncat足够的时间来处理结果很重要。

顺便说一句,我什么都没测试(只是写下来)

相关问题