Email – How to Forward to a Specific MTA Based on Email Address

bposemailpop3smtp

How can I forward incoming messages to a specific MTA based on the username portion of the recipient's email address? I would prefer linux-based software, but Windows would work too.

Background:
Our organization is transitioning from ISP-hosted POP3 mail to Microsoft Business Productivity Online Services (Exchange Online) and it would be nice to get coexistence working so that some users could be using the new system while other users continue to use the legacy system. As each user is migrated to the new system, their mail could be redirected to the appropriate server independent of other users and of DNS propagation.

Would this system work? Are there other migration schemes more appropriate to the scenario?

Edit 1
Our current ISP is running Postfix and Dovecot. They provide us with the ability to set up email forwarding, but only to a chosen email address. That doesn't really help us because their server will still use the MX record for delivery, which is what I want to bypass.

Best Answer

Postfix offers the ability to forward to different servers based on the recipient username by using transport tables. These tables can be stored as text files or in a database. For example:

legacy_user@example.com smtp:legacymail.example.com:25  
migrated_user@example.com smtp:newmail.example.com:25

Source: http://www.postfix.org/transport.5.html

Per-user transport tables could be used to enable a smooth gradual migration.

  1. Set up a postfix server that forwards mail for all users to the existing ISP
  2. Update DNS so MX record points to postfix server
  3. Wait for DNS to propagate.
  4. Edit transport table so mail for a few users is delivered to new server
  5. Update settings on computers for that batch of users
  6. Repeat steps 4-5 until all users have been migrated
  7. Update DNS so MX record points to new mailserver
  8. Shut down postfix server once traffic ceases

All users who are still using the legacy POP3 system can retain their SMTP settings, as long as that server is doing an MX lookup for users in the same domain. It won't work if their outgoing server is authoritative for the domain. It's possible that users on Exchange Server won't be able to send messages to users on the legacy system because messages will be delivered to the mailbox on Exchange Server.

To make this even more convenient for the sysadmin, Postfix could be integrated with a MySQL database and a web application that allows mail delivery to be toggled for batches of users.