2

In a CentOS 7 server with postfix and mailx, my ~/.mailrc file contains:

set MAIL=/root/Maildir
set folder=mail  

This enables mail from the root user's Maildir to be reviewed when the root user types in mailx at the terminal. However, the above configuration does not allow any of the other users on the CentOS 7 machine to be able to see their Maildir mail when they type mailx in the terminal when logged into their accounts.

How can I set global configuration of server to allow each of the other users to also see their Maildir email when they log into their accounts in the terminal and type mailx? Do I create a separate .mailrc for each user? If so, where do I put it? And what do I add to .mailrc?

The seed for this came from masegaloeh.

CodeMed
  • 315
  • 1
  • 8
  • 21

1 Answers1

0

A common solution is to use an existing file or a new one called mail.sh in /etc/profile.d/:

MAIL=~/Maildir

At login, the scripts in /etc/profile.d/ are executed by the user's shell and thus MAIL is set correctly for all users.

sebix
  • 4,313
  • 2
  • 29
  • 47
  • As root, I tried `nano /etc/profile.d/mail.sh`, the put `MAIL=~/Maildir` in that file and saved it. Then I stopped and started `postfix`. I then logged in as `username` and typed `mailx`, but it showed no emails for `username`. So I tried `mailx username@localhost` and sent a new email to `username`. Then I typed in `mailx` again, but it still showed no emails for `username`. Do I need to delete `.mailrc` to make your solution work? What am I doing wrong? – CodeMed Jan 06 '15 at 21:36
  • What does `echo $MAIL` give? This has nothing to do with postfix, just an issue of setting variables for the shell. `source /etc/profile.d/mail.sh` loads the file explicitly, maybe this show permission errors or so? – sebix Jan 06 '15 at 21:40
  • `echo $MAIL` gives `/var/spool/mail/username` – CodeMed Jan 06 '15 at 21:41
  • `nano /var/spool/mail/user` gives an empty file as well. – CodeMed Jan 06 '15 at 21:43
  • And this after loading the file directly using `source`? Very weird. You can also try putting it in `/etc/profile` to see if that works. – sebix Jan 07 '15 at 07:43
  • The shell login variables don't get expanded when performing mail lookup with `mail -u USERNAME`, since you're not loging in as that user into a terminal session, e.g. – ILMostro_7 Oct 31 '17 at 17:47