Migrate sendmail inbox to a new mailserver


Many sites suggest using procmail to parse the sendmail inbox to forward portions of your email for various purposes, but I haven't found a site that just states how to send the mail to a new mailserver.
procmail's formail is the correct command to use and it is simple.
You can forward either the inbox/mbox in the users directory or the users mailbox residing in /var/mail (/var/spool/mail).
Login as root or as the user.
cd /var/mail # or to the user's home directory
cat mailboxname | formail -s sendmail -oi emailname@newaddress
Example:

cat foo | formail -s sendmail -oi foo@bar.com

Note that there is no pipe between formail -s and sendmail. Putting a pipe there will cause all of the email to get lumped together. The -s tells formail to split the data into separate messages and formail then pipes each message to the next argument on the command line, and sends the rest of the arguments to the next command as well.
The from: address will be the from: address of each original message so you don't have to worry about logging in as any particular user. You won't even be able to tell that the new messages were forwarded.
Create a script to forward all email boxes with a modified month of April (so as to weed out old accounts) to the foobar.com server.
ls -al | grep " Apr " | awk '{print "cat "$9" | formail -s sendmail -oi "$9"@foobar.com"}' > sendscript
chmod u+x sendscript
vi sendscript # remove addresses that shouldn't be forwarded
./sendscript
rm sendscript

Lee Lofgren
Accounting Enhancements, Inc