4

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.

Exhaustive tests

If I 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 sleep 60.

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

Environment variables

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 mail, it shows me the test mail as expected.

[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 ~]$ 

Installing sendmail

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

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

  • perhaps the partly-working package provides incoming mail in a different directory than you expect. – Thomas Dickey Apr 30 '16 at 14:41
  • @ThomasDickey Good point but no. I can see mail being delivered to /var/spool/mail in both cases. – sourcejedi Apr 30 '16 at 15:02
  • This is strange. It's bash that does the checking of mail, so it should be independent of the MTA. My guess is that MAIL, MAILPATH, and/or MAILCHECK isn't set properly in your shell. – mkomarinski May 12 '16 at 17:49
  • Indeed, but I've checked the environment variables now and I can't see what's wrong! See updated question. – sourcejedi May 12 '16 at 20:04
  • Update: turns out I was testing wrong. However bash mail notifications assume that pam_mail is working. Unfortunately it's not, and so far I've failed to either enable or debug it. – sourcejedi May 12 '16 at 21:47
0
+100

Configuration for reporting on the status of mail at login time is handled by pam_mail. Check the corresponding file (e.g. /etc/pam.d/ssh) and make sure that you have a line that looks something like this:

session    optional     pam_mail.so standard noenv

May be different depending on your distribution. Check your distro documentation to see how it should be set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.