简体   繁体   English

验证邮件状态Bash脚本

[英]Validate Mail Status Bash Script

I' doing something like this: 我正在做这样的事情:

echo "TEST MAIL" | mail -s "subject" "SOME@MAIL.COM"

it's send ok! 发送成功! but i must validate in the shell script if the mail was sent or not. 但是我必须在shell脚本中验证邮件是否已发送。

I don't find some way to validate if the mail was sent or not. 我没有找到验证邮件是否已发送的方法。

EDIT: 编辑:

The only validation that i have is if the return value in the mail app is 0 我唯一的验证是,如果邮件应用程序中的返回值为0

if [ "$?" = "0" ]; then
    echo "Mail enviado a: $destinatarios"

else
    echo "Mail NO enviado a: $destinatarios"
fi

You should define what "sent" means for you. 您应该定义“已发送”对您的意义。 Return status of "mail" specifies only if the message was accepted by local MTA or not. 返回状态“邮件”仅指定邮件是否被本地MTA接受。

There are still many things that may happen to prevent delivery to the final recipient. 仍然有很多事情可能会阻止交付给最终收件人。 Beginning with there being no network connection on the local machine and ending with the recipient overlooking your message in his/her Inbox. 从本地计算机上没有网络连接开始,到收件人在其收件箱中忽略您的邮件开始。

Mail delivery is asynchronous. 邮件传递是异步的。 There are mechanisms for requesting delivery and read receipts, which seldom work. 有一些请求递送和阅读回执的机制,很少起作用。 You may have better luck processing non-delivery reports. 您可能会更好地处理未送达报告。 However, all of them may take arbitrary time to arrive. 但是,所有这些都可能需要花费任意时间才能到达。

For that matter, I would say zero exit status of "mail" is as good an indication of a successfully-sent message as you can get with reasonable effort. 就此而言,我想说的是“邮件”的零退出状态,是您尽力而为获得的成功发送消息的一个很好的指示。

如果您将电子邮件发送到应用程序内部,则可以将目标应用程序修改为“答复”,否则据我所知没有简单的方法.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM