27

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
7
  • What is the output of ls -l /var/mail command? Sep 27, 2013 at 20:05
  • it shows list of users that i have created : -rw-rw---- 1 1006 mail 2037 2013-08-10 12:38 abuse Sep 27, 2013 at 22:45
  • I know what it shows. And the output of ls -l /var/mail/fmaster? Sep 28, 2013 at 5:29
  • ` -rw------- 1 fmaster mail 2035 2013-08-10 00:16 fmaster ` Sep 28, 2013 at 11:12
  • This is not ok, it sould be: -rw-rw---- 1 fmaster mail 2035 2013-08-10 00:16 fmaster. And what is the output of groups fmaster? Sep 28, 2013 at 13:24

5 Answers 5

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
8
  • i dont think that is the problem i think this issue related to users permissions. Sep 27, 2013 at 23:29
  • @cjayomer So, what is the output of group command? Sep 28, 2013 at 5:26
  • the output of fmaster fmaster : fmaster sudo Sep 28, 2013 at 13:44
  • @cjayomer As I said, fmaster is not a member of mail group and this is a problem. See my new edits. Sep 28, 2013 at 13:52
  • 5
    When I tried this, the folder for my user in /var/mail/USER did not even exist. Is there a more simple way to add a user to the mail group and also simultaneously create the mail directory with appropriate permissions?
    – Startec
    Aug 17, 2016 at 4:07
12

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.

2
  • 1
    lol, this is probably easier -- wasn't able to confirm answer.
    – Thufir
    Jan 10, 2017 at 3:41
  • 1
    This answer is a meeelion times better and more intuitive. after doing this I was even able to fire up alpine (pine)! works wonders for CLI.
    – Thufir
    Jan 10, 2017 at 4:56
5

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.

3
  • Can you blend in the answer with the OP, I am confused. Jan 31, 2017 at 5:27
  • 2
    same as this answer in principle, but I'm upvoting both as this one explains much better than the original one.
    – Zanna
    Jan 31, 2017 at 5:59
  • How do I stop typing the body of the email lol
    – Jonathan
    May 14, 2021 at 8:47
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

0

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.

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.