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

Using telnet command in script for send mail

我想在 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
但它不起作用

你能帮帮我吗 谢谢

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 足够的时间来处理结果。

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