Tuesday, June 4, 2013

Forwarding already received (spooled) mail to an external address on Linux

After migrating my users to a Google apps domain, I still maintained the Linux server for a while. Several months later, one of my users then changed computers and all of a sudden she would sometimes experience "lost" email, where someone would insist they send her an email but she couldn't find in in her outlook. A few days later we then noticed that I had forgotten to set up her outlook to get mail from the Linux server. All the other users get their mail forwarded automatically to the new domain via the aliases file and only this user was  still "popping" to the new server.

After setting up my user's forwarding, I was left with the problem of her accessing those mails that had already been received on the Linux server and that week she was working away from the office and popping them into outlook wasn't possible. That's when I discovered a nifty little utility called formail. It formats your mail file properly and submits it to sendmail for forwarding to the new address using the command below:


cat spoolfile | formail -s /usr/sbin/sendmail her_new_address

Believe me, I have done this before but after a long while without doing anything similar on the Linux server, it took me quite a while of googling to come up with the correct command! Hope this saves you a bit of time if you need to do anything similar.