19

I am a graduate student and a relative Linux novice. This question is a sort of spin-off of my earlier question. My institution has a Ubuntu Linux cluster. I am just a user; I do not have sysadmin permissions, and I certainly do not have the expertise to be a sysadmin!

My question is, how do I find my local mail spool? As far as I know, I am not using a mail transfer agent. Answers to my previous question suggested that I look for a file /var/spool/mail/$USER, but unfortunately, I do not see a file corresponding to my user name. In /var/spool/mail/, using ls I only see two files: nobody and www-data, which are both extensionless files.

Do you have any other ideas of where I can look for my mail spool (which is probably local, since I do not have a mail transfer agent configured, as far as I know)?

6
  • 4
    try echo $MAIL – squarestack Jul 13 '13 at 18:00
  • 1
    Have you send an email to yourself? Mailbox files are usually created on "as needed" basis. – AnFi Jul 13 '13 at 18:37
  • @Shutupsquare This is interesting. When I type echo $MAIL, it returns /var/mail/myusername, where myusername is my username. But when I navigate to /var/mail/, the file myusername does not exist there. – Andrew Jul 13 '13 at 20:45
  • @AndrzejA.Filip Other than using at to send a local message when a scheduled process generates output, how can I try sending a message to myself? This is all so new to me. – Andrew Jul 13 '13 at 20:51
  • You may use the following command to send test email to yourself:(echo Subject: test; echo) | /usr/sbin/sendmail -i YOUR_LOGIN. Sendmail stub is provided by other MTA servers too (e.g. postfix, exim). – AnFi Jul 13 '13 at 21:03
21

Mail spools are typically under here:

/var/spool/mail/$USER

Where $USER is your username. For example on my Fedora Linux system:

$ ls -l /var/spool/mail/
total 1908
-rw-------. 1 root root 1943163 Jul 13 12:00 root
-rw-rw----. 1 rpc  mail       0 Dec 18  2010 rpc
-rw-rw----. 1 saml mail     689 Jul 12 19:38 saml

Mail spools however are not necessarily local. If you do not have this file then your mail is being maintained on another server. You can either interact with this server using protocols such as IMAP or POP3.

It is on this system where your mail spool is being maintained.

In some environments the mail spool can be shared out as part of a user's home directory, often times in a directory called mail ($HOME/mail). Other times it can be shared out as its own share under something like /mail/users/$USER.

It really depends on how the sysadmins within a given environment choose to do so.

1
  • 2
    Note: if there is a /var/mail, as in the question, it may be a symlink to /var/spool/mail, as in this answer, or the other way around. At least, that's the case on my home ubuntu laptop from System76. Removing files/folders from either directory would presumably delete the corresponding file from the other directory. – trysis Dec 1 '18 at 15:47
7

Unless your machine is misconfigured, the command mail (or other mail programs such as mutt) will access your local mailbox. Usually the local mailbox is either /var/spool/mail/$USER or /var/mail/$USER. If the mailbox is in a non-standard location, the system administrator may have configured the system to set the MAIL environment variable to the location of your mailbox.

If you've never received mail on that machine, then the file won't exist. Send yourself a mail, and the file will be created.

If any mail is ever delivered on this machine, then a mail transfer agent is running. You wouldn't ever interact directly with the MTA: it's something that the administrator set up.

The existence of the files /var/spool/mail/nobody and /var/spool/mail/www-data shows that there is (or was) an MTA running and delivering mail locally. They probably contain reports from cron jobs.

You will only be able to receive mail from other machines if that machine is configured to receive mail. In a multiple-computer environment, it is common to configure a single machine to receive all mail. This is indicated through DNS. If there is an MX record for a host, it indicates which host is to receive the mail intended for that host. You can see the MX record with host -t MX $HOSTNAME or dig MX $HOSTNAME.

Even if you are receiving mail locally, it's possible that it is redirected to another machine. Check if you have a file called .forward in your home directory: it contains an email address to redirect your mail to, or some other directive telling the MTA what to do when you receive mail. You may also have a .procmailrc file if the MTA is configured to use procmail to deliver the mail, which is fairly common.

6

You should find it in either /var/spool/mail/ (the traditional location) or /var/mail (new recommended location). Note that one may be a symbolic link to the other, so it's best to go to the one that is an actual directory (and not just a link). Here you should find a file called the same as your username, that is your mailbox. It should be owned by you, so you should easily be able to make a copy of it.

2
  • Unfortunately, /var/spool/mail/ and /var/mail/ each have only two files: nobody and www-data, neither of which are my username. Thanks for your time. – Andrew Jul 13 '13 at 20:37
  • @Andrew - the lack of your username in these directories just tells you that there hasn't been any mail delivered locally on that particular system. – slm Jul 13 '13 at 22:55
0

Did you check to see if you have postfix as a mail transfer agent (MTA) configured? The config file for Postfix will generally have a clue. Our Postfix config file is here: /etc/postfix/main.cf

In it there is a line that says this:

home_mailbox = Maildir/

So that lets us know that the mail directories (Maildir) are in each user's home directory.

In our case, we have Dovecot as our IMAP server, so we see Dovecot files in those Maildir directories. We also see subdirectories cur and new. If the mail has not been opened yet by your email client, it will be in the new directory. If it has been opened, it will be in the cur directory.

This information may be different for you if you have a different mail setup, but it is one possibility.

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.