Dec 272012
 

Yesterday I was setting up a new server for a client / friend. During the setup, we had a brief period wherein mail was delivered to mbox instead of to Maildir. That is, we had mail sitting in /var/mail/USER instead of ~USER/Maildir, for a number of values of USER.

At first, I tried using formail and procmail to send it to the local user. I did this using a method I found using Google. In short it involves adding this to ~/.procmailrc:

:0
*
! foo@example.com

This is the address to which you wish to forward the mail.

Then you issue this command:

sudo cat /var/mail/USER | formail -s procmail

Where USER is the email mbox that you wish to forward to foo@example.com

NOTE: I tried forwarding the mail to the local user (e.g. I put just foo in ~/.procmailrc but the mail server complained about a mail forwarding loop. I’m sure there’s an email way around that problem too. But in this situation, I forwarded the mail to other servers, such as gmail or yahoo.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

  2 Responses to “Forwarding mail in mbox to elsewhere”

  1. Helpful. And if you want to send an email out an mbox-type file to an external recipient you can do it like this:

    </var/mail/user formail +3 -2 -s sendmail recipient@wherever.com

    where /var/mail/user is the mbox-type file, the ‘+3’ says ‘skip the first 3 messages in the mbox file’, and the -1 says ‘send two messages max’. The messages will still be in the mbox afterwards, if you want to remove them you need to do this separately.

    • Thank you.

      When I recently had issues like this, I wound up importing the mbox into my IMAP client. Most clients have an import or attach feature. From there, I moved / copied the messages to where I wanted them.

      However, your solution has the benefit of going through the delivery process (eg filtering).

      One potential issue: redeliver of mail. Given the mail was already delivered to this mailbox, will a mail delivery loop error be raised?