29

When i run the command. su - fmaster mail

I get the error:

Cannot open mailbox /var/mail/fmaster: Permission denied No mail for fmaster

also i sign in as fmaster. terminal -> mail.

/var/mail/fmaster: Permission denied No mail for fmaster

I tried to execute this code but i still get the same error..

sudo touch /var/mail/$USER
sudo chown $USER:mail /var/mail/$USER
sudo chmod o-r /var/mail/$USER
sudo chmod g+rw /var/mail/$USER
Omer Stimpack
  • 471
  • 2
  • 7
  • 13

5 Answers5

21

The user fmaster is probably not in the mail group. You can run groups command to check in which groups you are.

To add fmaster to the group mail use the following command:

sudo adduser fmaster mail

And after run:

sudo chmod ug+rw /var/mail/fmaster
Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
14

If you've followed Radu Rădeanu's advice, keep in mind that

/var/mail/fmaster

won't exist until it receives its first email. So you should send fmaster an email before further troubleshooting.

J Smith
  • 241
  • 2
  • 3
9

I confirmed that sending an email to the user for the first time did create the mail directory for the user. Just do:

mail fmaster@localhost

/var/mail/fmaster directory will be created with the correct permision. The user, fmaster, can then use the mail command to read the mail.

Zanna
  • 72,312
Hay T
  • 91
  • 1
  • 1
1

Try setting the mail variable. The emails you may be sending could be directed to this directory.

MAIL=/home/your_user/Maildir

Then try the mail command again.

mail

https://help.ubuntu.com/community/PostfixBasicSetupHowto

therefriedbean
  • 349
  • 1
  • 2
  • 8
1

The first thing to sort out is which mail program you are using when you run mail.

Do this:

$ command -v mail               # (Similar to the old `which`.) You'll likely see:
/usr/bin/mail

Then see what this is:

$ ls -l /usr/bin/mail           # And now you'll likely see (at least for Debian):
lrwxrwxrwx 1 root root 22 Feb 17  2019 /usr/bin/mail -> /etc/alternatives/mail

Then see where that is:

$ ls -l /etc/alternatives/mail  # And I get:
lrwxrwxrwx 1 root root 23 Dec 10 19:58 /etc/alternatives/mail -> /usr/bin/mail.mailutils

And finally check this out:

$ ls -l /usr/bin/mail.mailutils
-rwxr-xr-x 1 root root 218160 Nov 18  2020 /usr/bin/mail.mailutils

So when you are running mail, you are actually running mail.mailutils. Also notice that it's owned by root, but everyone has permission to run read and execute it.


Now looking at the configuration documentation for the mailutils package, we see that there are many possible methods for configuration, including:

  1. System wide configuration in /etc/mailutils.conf, or

  2. User over-rides in /home/[your-username]/.mail, or even

  3. Startup overrides with mail --file /var/mail/[your-username]

Settings from method 2 overrides method 1, and method 3 overrides both methods 2 and 1.

One important point is that the mailbox format doesn't have to be mbox (single large files with multiple messages in each file). It can also be mailbox format (or a tree of individual files). There are also other formats available, like mh.

For the first two options above you will likely want to use a URL

mailbox {
       # Create mailbox URL using PATTERN.  
       #   (preferred way of configuring mailbox locations)
       mailbox-pattern PATTERN;
}

Like this:

mailbox { mailbox-pattern "/var/mail/${user}"; }

Another important point is that your system has two places for your mailboxes:

  • Incoming messages are in one place, typically /var/mail/[username], and
  • read messages are, depending on the mailbox format, in either:
    • /home/[your-username]/mbox or
    • /home/[your-username]/mailbox/*.

If you're using any of the mailutils programs, you can see how your system is configured with:

$ mailutils info           # which gives you something like this:
VERSION=3.10
SYSCONFDIR=/etc
MAILSPOOLDIR=/var/mail
SCHEME=mbox
LOG_FACILITY=mail
...

Finally, don't confuse the two different uses of the term 'spool' as related to mail. exim4 has what it calls a spool, which is where it holds messages waiting to be delivered, and then when you go to read emails some people say you're reading from the mail spool. It is probably better to remember that you're reading from a mailbox, and that only exim4 has a spool. For locally delivered messages exim4 reads a message from it's spool, and puts it into your mailbox, normally in /var/mail/[your-username] if you're using mbox.

Also note that you must be in the mail group, as others above have clarified. What they didn't tell you was that you might need to reboot to make your addition to the mail group stick and show up when you open a terminal window. Simply opening another terminal windows won't have you in that group, and logging out and re-logging in won't fix it either.


So now that you know which mailbox you're trying to read, you can look at it's permissions to see if you need to update them or not.