1

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.

  • Do you have POP3/IMAP access to michael's mailbox? – Marco Marsala Oct 20 '15 at 16:24
  • For mydomain.com I've all kind of access. For hisdomain.com don't, but there's a POP3 server for sure; IMAP I don't know but it's likely. If you're thinking about a dovecot synchronization, I don't have the credentials to connect to michael@hisdomain.com, even more, I guess hisdomain.com uses mailenable. So, the only way left I think is forwarding mails. – Peregring-lk Oct 20 '15 at 16:36
3

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

  • IMAP synchronization is an alternative solution, but I would like to know at least a way to forward only a mail from terminal, as MUAs do. With a loop I could resend then so many mails as needed. – Peregring-lk Oct 21 '15 at 12:27
  • what format are the files, mbox or maildir (or something else) – Jacob Evans Oct 21 '15 at 12:38
  • On my server maildir, and on the other I guess maildir also. Can I just "copy" the folder structure from a server to a different one? For example, from dovecot to mailenable? What does it happen with POP3 and IMAP UIDS in such a case? – Peregring-lk Oct 21 '15 at 12:54
  • UUIDs should stay the same of you copy, imap/pop3, they will change if you resend – Jacob Evans Oct 21 '15 at 12:55
2

If you have IMAP access to michael@hisdomains.com you may consider the IMAP upload feature, available in all mail clients. Just configure both accounts in a client (for ex. Thunderbird, Outlook, Windows Live Mail) and drag'n'drop messages from one inbox to another. Or there are plenty of automatic IMAP migration tools.

If you haven't IMAP access, you can use the "Forward" feature - available in Horde webmail or mutt command line mail client - that will preserve the original sender (mind the spam filter on the recipient)

0

You can use sendmail with your messages files (Maildir) as input and parameter -i to not treat a line with only a . character as the end of the input.

for f in *; do sendmail -i michael@hisdomain.com < $f; done
-2

You have to configure sieve plugin for dovecot. Then just create script for specific user that contain the next code:

require ["copy"];
# rule:[redirect]
if true
{
        redirect :copy "michael@hisdomain.com";
}

All messages passed from MTA to LDA (dovecot's deliver) will be stored in mailbox as well as redirected to another MTA.

  • 4
    The question was specifically about already delivered messages. – wurtel Oct 21 '15 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.