如何让 mailx 通知我有新邮件?

如何让 mailx 通知我有新邮件?

我正在尝试在我的服务器上设置 mailx。在一台服务器(Raspbian)上,我收到带有消息You have new mail(或类似内容)的新邮件。在另一台机器(Raspbmc)上,我从未收到此通知。

在两台机器上,~/.bashrc本质上是相同的。/etc/mail.rc在后者系统上不存在,但在前者上存在,内容如下。

set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To

编辑

我还应该提到我是通过 SSH 连接的。

正如所暗示的这里,我尝试/etc/pam.d/sshd从工作的 Raspbian 服务器复制到损坏的 Raspbmc 服务器,然后注销并重新登录,但它没有解决问题。该文件包含

# Print the status of the user's mailbox upon successful login.
session    optional     pam_mail.so standard noenv # [1]

最后我还确认了访问时间/var/mail/pi早于修改时间。 (无论如何,文件系统都是挂载的noatime。)

答案1

AFAIK 邮件通知是一个 shell 函数,在 bash 中通过设置 MAIL 环境变量来实现,它与命令几乎没有任何关系mailx。在不同的 shell 中,它的功能可能有所不同。

在我的 RHEL 系统中,它的配置/etc/profileMAIL="/var/spool/mail/$USER"

一个简单的 echo $MAIL 将显示它是否已设置。

乍一看,它仅适用于 mbox 风格的邮箱,不适用于 Maildir,其中每条消息都存储在单独的文件中。

从 bash 手册页:

   MAIL   If  this  parameter is set to a file name and the MAILPATH vari-
          able is not set, bash informs the user of the arrival of mail in
          the specified file.
   MAILCHECK
          Specifies  how  often  (in  seconds)  bash checks for mail.  The
          default is 60 seconds.  When it is time to check for  mail,  the
          shell  does  so  before  displaying the primary prompt.  If this
          variable is unset, or set to  a  value  that  is  not  a  number
          greater than or equal to zero, the shell disables mail checking.
   MAILPATH
          A colon-separated list of file names to  be  checked  for  mail.
          The message to be printed when mail arrives in a particular file
          may be specified by separating the file name  from  the  message
          with a '?'.  When used in the text of the message, $_ expands to
          the name of the current mailfile.  Example:
          MAILPATH='/var/mail/bfox?"You  have  mail":~/shell-mail?"$_  has
          mail!"'
          Bash  supplies  a default value for this variable, but the loca-
          tion of the user mail files that it  uses  is  system  dependent
          (e.g., /var/mail/$USER).

在同一系统上的 csh 手册中,它似乎是小写的

邮件可以设置 shell 变量来定期检查新邮件。

   mail    The names of the files or directories  to  check  for  incoming
           mail,  separated  by  whitespace,  and optionally preceded by a
           numeric word.  Before each prompt, if 10  minutes  have  passed
           since  the last check, the shell checks each file and says 'You
           have new mail.' (or, if mail contains multiple files, 'You have
           new  mail  in  name.')  if the filesize is greater than zero in
           size and has a modification time greater than its access  time.

           If  you  are  in  a  login shell, then no mail file is reported
           unless it has been  modified  after  the  time  the  shell  has
           started  up,  to  prevent  redundant notifications.  Most login
           programs will tell you whether or not you have  mail  when  you
           log in.

相关内容