Ubuntu – Can exim be configured to send all emails externally

emailhostnameserver

How do I configure exim4 to route all emails via a third-party SMTP server when the sender's domain, recipient's domain, and server hostname all match?

I followed this great answer and have exim4 sending emails to addresses at other domains tested and working from an Ubuntu server. My only issue is that emails where both the sender and recipient share the same domain as the server hostname, they never leave the server (and this is the expected behavior).

For example, sending from test@example.com –> test@example2.com works fine, but sending from account1@example.com –> account2@example.com just routes the mail locally to /var/mail/account2, without passing through the third-party SMTP server.

I'm using Google Apps at my own domain and want to send emails from server@example.com to me@example.com from a machine with the hostname example.com.

I want to route them through Google's SMTP server so I see them in my other email clients. Is this possible?

Very similar questions (but for postfix) here and here.

Best Answer

Take a look at the setting and use of

domainlist local_domains

You should find some uses in the access lists before things get interesting in the router section. My box at home has this one as first router:

    send_to_gateway:
      driver = manualroute
      domains = ! +local_domains
      transport = remote_smtp_smarthost
      route_list = * SMARTHOST

clarification: the following router will be applicable to all emails going to the contents of ˋlocal_domainsˋ

    send_to_gateway:
      driver = manualroute
      domains = +local_domains
      transport = remote_smtp_smarthost
      route_list = * SMARTHOST

The transport used is defined in the transport section of the exim config, you should already have one (possibly with a different name), which pushes your mail to other places. The route_list variable tells exim to push all mails of this router to the server SMARTHOST.

You should invest some time and read the fine exim manual. It will help with non-standard settings that are beyond what ubuntu's simplified configuration can do.