I installed the
sendmail package on Fedora 23. So now I have
/usr/sbin/sendmail that actually kind of works. Except now I don't get mail notifications in the bash shell. Why not?
EDIT: I thought the bash notification was broken (and worked with esmtp, as described below). However the notification at login was easier to test, so I'm afraid I conflated the problem.
Notification at login didn't work, but I think that's actually the responsibility of pam_mail, not bash. I thought notifications at login did work with esmtp, but I notice
grep -r pam_mail /etc/pam.d doesn't show any results. Unfortunately enabling pam_mail as per the documentation doesn't seem to do anything, even though it's supposed to always print, e.g. "No mail". It also has a
debug option, but that didn't display anything to the user nor syslog (aka the journal).
mail alan; sleep 60 does generate a notification.
However if I
mail alan; logout then I don't get any notification when I log in again. Even after
sleep 60. Obviously this is undesirable.
It seems like bash assumes
pam_mail is working. So if mail is available at login time, then bash makes sure not to notify a second time for the same mail.
So the real problem is that pam_mail is not working.
This realisation required exhaustive tests because I'm dumb.
mail alan, then open a second login and run
sleep 60, I get a notification in one login (only). It's not obviously a problem with a logout script, because
mail alan; sleep 60 works even if I open a second login and log it out immediately.
Testing with sending mail from a second user, suggests that the notifications don't work if you're not logged in when the mail is sent.
Once bash has shown a notification, it's not showing it again, e.g. after a second
I thought it might be comparing the file's access time to the modification time, but that doesn't seem to be the case.
$ stat $MAIL File: ‘/var/spool/mail/alan’ Size: 859 Blocks: 16 IO Block: 4096 regular file Device: fd00h/64768d Inode: 655929 Links: 1 Access: (0660/-rw-rw----) Uid: ( 1000/ alan) Gid: ( 12/ mail) Context: unconfined_u:object_r:mail_spool_t:s0 Access: 2016-05-12 22:17:28.907175410 +0100 Modify: 2016-05-12 22:18:03.177899774 +0100 Change: 2016-05-12 22:18:03.177899774 +0100 Birth: -
Example below. This is after I sent a test mail to myself. So when I log in, I expect a notification. If I go on to run
[alan@localhost ~]$ ssh alan-nuc Last login: Thu May 12 20:50:54 2016 from 172.16.9.242 [alan@alan-nuc ~]$ echo $MAIL /var/spool/mail/alan [alan@alan-nuc ~]$ ls -l $MAIL -rw-rw----. 1 alan mail 850 May 12 20:56 /var/spool/mail/alan [alan@alan-nuc ~]$ echo $MAILCHECK 60 [alan@alan-nuc ~]$ echo $MAILPATH [alan@alan-nuc ~]$
Fedora Workstation ships with a non-working
/bin/sendmail (esmtp package).
It can be set up by install maildrop and setting
mda="maildrop -d %T" in /etc/esmtprc. This allows mail from a user to themself, and from root to anyone. With esmtp and maildrop, bash shows mail notifications as expected.
However esmtp doesn't work for mails from the
cron daemon. esmtp logs "permission denied" when trying to read the message to deliver. https://bugzilla.redhat.com/show_bug.cgi?id=1303305 Specifically, when trying to re-open
/dev/stdin, which is generally expected to succeed (equivalent to
dup()). So it's probably SELinux, but there is no SELinux (AVC) denial logged, it's probably
Installing the old sendmail package replaces the sendmail command provided by esmtp. I thought that would be a simple way to bypass the new bugs, but now I have yet another bug :(.