从 Linux 命令行发送电子邮件的不同方式

发布于 2024-10-16 09:58:34 字数 580 浏览 7 评论 0原文

对于我们的网络项目,我们需要一个可靠的电子邮件分发机制。 则发送通知电子邮件,

  1. 由于过去的糟糕经历,我编写了一个 bash 脚本(每小时执行一次),如果qmail-send 进程未运行,
  2. 邮件日志中有太多失败

用于发送通知电子邮件我显然不想依赖qmail,因为如果qmail-send进程没有运行,qmail将不可用。但是,以下命令通过 qmail 发送通知电子邮件:

echo "failure rate critical" | mail -s "qmail notification" [email protected]

What's the simple way to send e-mail from the linux command line without qmail?我可以使用发送邮件吗?

如果你们有更智能的警报系统来监控 qmail,请告诉我。

For our web projects, we need a reliable e-mail distribution mechanism. Due to bad experiences in the past, I have written a bash script (executed hourly) which sends a notification e-mail if

  1. the qmail-send process is not running
  2. there are too many failures in the mail log

For sending the notification e-mail I obviously don't want to depend on qmail, since qmail will be unavailable if the qmail-send process is not running. However, the following command sends the notification e-mail via qmail:

echo "failure rate critical" | mail -s "qmail notification" [email protected]

What's the easiest way to send e-mail from the linux command line without qmail? Can I use sendmail?

If you guys have smarter alarm systems to monitor qmail, please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

高速公鹿 2024-10-23 09:58:34

调用 /usr/sbin/sendmail 二进制文件。无论您使用哪种 MTA,它通常都是可用的,并且如果它名为 sendmail,您可以确定它支持标准的 sendmail 接口。

最简单的使用方法是调用 sendmail -t,然后将包含有效 To 标头的电子邮件写入其标准输入。如果省略 -t,则必须将收件人地址作为命令行参数传递。

另一种解决方案是使用 SMTP,但如果您需要从 bash 脚本发送电子邮件,这显然是一个糟糕的解决方案,因为 Bash 中没有标准库包含通过 smtp 发送电子邮件的函数(与 python 不同,在 python 中您无法轻松发送邮件)使用 sendmail 但通过 SMTP)。

Invoke the /usr/sbin/sendmail binary. It is usually available no matter which MTA you use and you can be sure it supports the standard sendmail interface if it's named sendmail.

The easiest way to use it is invoking sendmail -t and then writing the email including a valid To header to its stdin. If you omit -t you'll have to pass the recipient address as a commandline argument.

Another solution would be using SMTP but if you need to send emails from a bash script this is clearly a bad solution as there are no standard libraries in Bash which contain functions to send an email over smtp (unlike in python where you cannot easily send mails using sendmail but over SMTP).

若能看破又如何 2024-10-23 09:58:34

您有一个 POSIX 中的mail 实用程序。如果您只使用 Linux,sendmail 就可以(但是您依赖于系统的(错误)配置,对吧?)。

总而言之,SMTP协议并没有那么难。我想说你可以用纯 SMTP 进行交谈。这大约是为一封普通邮件发出的四个命令。而且它是便携式的:)
但如果出现并发症,可能会导致 PITA...

You have a mail utility in POSIX. If you're only for linux, sendmail is ok (but then you rely on the system's (mis)configuration, right?).

All in all, SMTP protocol is not that difficult. I'd say you can talk in pure SMTP. It's about four commands to issue for a trivial mail. And it's portable:)
But if there are complications it may result in PITA...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文