Configure server to foward unroutable emails to another email server

emaileximmail-forwardingmx-record

Is it possible to configure a Linux mail server (we're running exim) to forward unhandled emails to another server? Here's an example of what I'm trying to accomplish:

  • an email get's send to user@domain.com
  • the MX record for domain.com points to server1 so the email goes to server1
  • if server1 doesn't have an email forward or mailbox for user@domain.com it forwards the email to server2 that receives the email as if it was originally sent to it (as if the MX record pointed to server2 directly)

Is something like this possible? If it is, any information you can provide on how to accomplish this is highly appreciated.

Thanks.

Best Answer

It could be done with a router placed after all the routers that match local users.

An alternative would be to put a callout router early in the list that calls out to the second server and accepts mail if the user exist there. This would be my preference.

Routing would be:

  • Route to second server if address exists there.
  • Route locally for local addresses.
  • Reject.

EDIT Something like this should forward all unhandled mail for local domains to notlocal.host.ref.example. Mail for root is not forwarded. This router has not been verified, and does not handle address validation. You may need to remove the cannot_route_messages from a prior router.

  notlocal:
   driver = manualroute
   transport = remote_smtp
   domains = +local_domains
   route_list = +local_domains  notlocal.host.ref.example
   local_parts = ! root
   cannot_route_message = Unknown user

Basically this is the final delivery router with the transport changed and check_local_user removed. Test before using.

Related Topic