Dovecot/postfix: forward all current messages

dovecotmail-forwardingpostfixsendmailsmtp

What I'm try to achieve it's pretty simple, and, after googling, its hard to believe I've been unable to find a solution.

What I want is to forward all current messages (already delivered) of an user (michael@mydomain.com) to another external and out of my control account (michael@hisdomain.com). The source server (the ours) is an Ubuntu Server 14.04 with postfix/dovecot.

The only thing that comes to mind is through a bash script, for example, iterating over every plaintext mailbox's message, manipulate their contents to erase headers, and forward them using sendmail, but I think there should be a simple tool or option of a very well-known tool to specify the destination account and the mail filepath to be forwarded.

Best Answer

Building on Marco's answer, I've used a few IMAP Sync utilities to accomplish this, works from windows/*nix and supports SSL, http://imapsync.lamiral.info/

If you are unable to request temporary permissions (reset password for a day or so) I would configure your account on his email client to download it into his mailbox that way, otherwise yes you'll be sending all those emails FROM your mailbox and not the original senders which would be a pain.

You could also attach the messages and forward them as attachments. I'm not sure how you could do this with a script but someone could figure it out.

mbox solution

sudo apt-get install procmail

myemail=username@example.com

cat /var/spool/mail/root |
formail -k                \
        -X From:          \
        -X Subject:       \
        -X Message-Id:    \
        -X Date:          \
        -X To:            \
        -I "To: $myemail" \
        -s /usr/sbin/sendmail -t -f $myemail

Source: resend-mail-thats-locally-stored-in-a-mbox-format-on-a-linux-box-to-a-working-email-address