Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Access local mail via UNIX
I wanted to read my local mail (stored in /var/mail/$USER) with, so I played around a little. Here is the result. I don't know if there is an easier way in Panther to do this. First open a terminal. Type in:
cd ~/Library/Mail/Mailboxes/
Create a new Mailbox:
mkdir Local.mbox
(or whatever name you like) Change the permissions for the mailbox:
chmod 755 Local.mbox
Create the Info.plist (with vi):
vi Local.mbox/Info.plist
Go to the INSERT mode by hitting i, and paste the following XML statements (the !DOCTYPE line needs to be one line, not two -- shown as two here for width reasons. Replace the return with one space):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
<plist version="1.0">
Exit vi by pressing the Escape key, then typing :wq. Now link to your mail in /var/mail:
sudo ln /var/mail/$USER  Local/mbox
That's it...

[robg adds: I thought we'd run something like this before, but I can't find it anywhere ... so my apologies if this is a dupe!]
  • Currently 3.25 / 5
  You rated: 4 / 5 (4 votes cast)

Access local mail via | 17 comments | Create New Account
Click here to return to the 'Access local mail via' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Access local mail via
Authored by: bschoate on Mar 18, '04 11:19:30AM

The hardlink fails because I'm using FileVault:

ln: Local/mbox: Cross-device link

Any suggestions?

[ Reply to This | # ]
Access local mail via
Authored by: gospodin_david on Mar 18, '04 12:00:39PM

try a symlink instead of a hard link use "ln -s" instead of just "ln". Symbolic links work across devices.

[ Reply to This | # ]
Access local mail via
Authored by: Stephan Leemburg on Mar 19, '04 04:01:46AM

You should not use a hardlink, but a softlink. Use:

sudo ln -s /var/mail/$USER Local.mbox/mbox

for this.

[ Reply to This | # ]
Access local mail via
Authored by: celkins on Mar 18, '04 11:41:40AM

That last line has a typo. It should be:
sudo ln /var/mail/$USER Local.mbox/mbox

Also, if you're symlinking your own mailbox, the 'sudo' is unnecessary.

[ Reply to This | # ]
Access local mail via
Authored by: googoo on Mar 18, '04 11:44:14AM

I think there is a typo in the ln statement. It should read

sudo ln /var/mail/$USER Local.mbox/mbox


PS. Great hint! I have been wanting to do that for some time!

[ Reply to This | # ]

Access local mail via
Authored by: googoo on Mar 18, '04 11:58:29AM

Sorry for the duplication. I guess I was a little slow hitting the send button!


[ Reply to This | # ]
Access local mail via
Authored by: bschoate on Mar 18, '04 12:12:37PM

Well, it sorta works. Sorta.

I edited /etc/postfix/ and uncommented the home_mailbox setting:

home_mailbox = Mailbox

This makes ~/Mailbox the spool file. So I can create a hard link now to the mbox file.

BUT-- once you purge deleted messages, recreates the mbox file, destroying the link in the process.

So instead, I think I'm going to use this for postfix:

home_mailbox = Library/Mail/Mailboxes/Local.mbox/mbox

That works if the supporting tree exists.

My only complaint at this point is that it doesn't update the new mail count when there are new local messages. What's up with that?

[ Reply to This | # ]
There has to be a way to make it work!
Authored by: googoo on Mar 18, '04 12:50:42PM

I had the same problem with the link being clobbered by! As for the message count, automatically updates the folders for accounts that are enabled and set to be checked automatically (in the Mail -> Preferences -> Accounts menu under the Advanced Settings tab). It seems like the only way that updates other folders is when something forces it to look at them.

There has to be a way to make this all work! I suppose one could write a script to re-enable the link to /var/mail/$USER and update the folder contents in Does anyone have a better solution?


[ Reply to This | # ]
Access local mail via
Authored by: gorkonapple on Nov 14, '04 11:37:08AM

THIS is the real solution to this. I tried the other way and it just resulted in me not even being able to use mail from the command line. Changing the postfix settings changed this. I wanted to access mail locally because iPodderX creates a cron job that automagically checks the feeds. Because cron sends a mail, I looked on this as a opportunity to have my mail tell me when the feeds have been updated, but the mail all goes unseen if you don't go to the command line often. This simple fix corrected that.

[ Reply to This | # ]
Symlink in the opposite direction
Authored by: ethomas on Mar 18, '04 12:52:59PM

As mentioned, if your Home directory is on a different volume, you can't create a hard link between /var/mail/$USER and /Library/Mail/Mailboxes/Local.mbox/mbox

You can however create a symlink, but the problem here is that when you quit, it rewrites /Library/Mail/Mailboxes/Local.mbox/mbox, destroying the symlink.

You can get around this by creating the link in the opposite direction:

sudo ln -s ~/Library/Mail/Mailboxes/Local.mbox/mbox /var/mail/$USER

You will need to use sudo since the /var/mail directory is owned by root, group-owned by mail, and is not world-writable.

[ Reply to This | # ]

Access local mail via
Authored by: bschoate on Mar 18, '04 12:59:31PM

Unfortunately, I see no way to add "On My Mac" (the account pseudonym for local mailboxes) to the Accounts list.

[ Reply to This | # ]
Seems like too much work
Authored by: NrTal on Mar 18, '04 03:54:11PM

If you are receiving email in you Unix account, isn't there a mail server running locally whether Postfix or Sendmail? I was able to set mine in Mail up as a normal mailbox, using localhost as the server. If I log into Terminal with another user and send mail using unix's mail command to my short user name Mail finds it fine.

Mind you, I set this up as part of an ongoing project to do local web development. I used PostFix Enabler to get it running, but I don't think it did anything I wouldn't have done through Unix had I not been looking for a GUI. But from the first hint it sounds like there would be a server running on localhost already, so maybe someone could explain why just using it as such wouldn't work.

[ Reply to This | # ]
Seems like too much work
Authored by: NrTal on Mar 18, '04 03:57:04PM

After I hit Submit I went to close Postfix Enabler and noticed the 'Setting up' button that ends up going to their website, so that's how I found out how. Still, it seems to me that no matter how you've got it running locally Mail should be able to see it if it's a mail server.

[ Reply to This | # ]
Seems like too much work
Authored by: jbc on Mar 19, '04 12:59:29PM

I'm curious if this actually works for you. My experience is that Panther Mail is broken with respect to checking local mail using a server. Installing a POP3 server and checking /var/mail mailboxes from Mail worked fine in Jaguar; Panther's Mail will *only* let me check the local mailboxes if my dial-up connection is active.

I have fetchmail and exim routing all my mail to the local mail spools in the background while my connection is up; most of the time, I'm *not* connected when I finally decide to read my mail. Mail no longer works for this, so ended up trashing Mail and switching to a client that will let me check the local mailboxes correctly.

[ Reply to This | # ]
Seems like too much work
Authored by: ethomas on Mar 19, '04 06:49:07AM

The point here is that you can now (once again) use to read your local unix system mailboxes (i.e. johndoe@localhost) without running a local mail server. If I remember correctly, in OS X 10.0 could do this, but Apple pulled this functionality from subsequent versions.

Anyway, this is very handy if, for example, you use cron regularly:

From the cron man pages:

When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists).

[ Reply to This | # ]
Access local mail via
Authored by: rwmitchell on Nov 09, '04 10:37:57AM

This no longer seems to work in 10.3.6.

Everything seems to work at first, but after deleting mail from the new mailbox, rewrites the Local.mbox/mbox file, breaking the link.

[ Reply to This | # ]
Access local mail via
Authored by: rwmitchell on Nov 09, '04 10:54:37AM

I think the hint can be corrected.

mv /var/mail/$USER Local.mbox/mbox
ln -s ~/Library/Mail/Mailboxes/Local.mbox/mbox /var/mail/$USER

This causes any mail put into /var/mail/$USER to be redirected via the symbolic link into the Local.mbox/mbox file. can erase and rewrite the mbox file to its little heart's content without affecting the other end of the link. The symbolic link points to the filename that will always exist.

The old hint failed because creates a temporary mbox file when saving the changes, unlinks the original mbox file, and then renames the temporary file to mbox - which breaks the link.

[ Reply to This | # ]