All HowTo's

Use Formail to split and send old mbox emails

This article demonstrates how to process a single mbox file with multiple emails within it. We will split the file into individual emails and then send those emails to a specific email account.

First we split the mbox into individual files – one email per file:

cat /var/spool/mail/root | formail -ds sh -c 'cat > old_mail/msg.$FILENO'

Next we take each file and send that file (as the body of the new email) to a specific email account. In this case we’re sending to “[email protected]”:

for var in `ls old_mail/msg.*`; do mail -s "Old email never delivered - ${var}" [email protected] < $var; done

At this point you're complete. The emails have been split and send individually to a specific email account.

Leave a Reply

Your email address will not be published. Required fields are marked *