开发者

Different ways of sending e-mail from linux command line

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" my@email.com

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

If you guys have smarte开发者_如何学编程r alarm systems to monitor qmail, please let me know.


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).


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜