0

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.

1

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.

  • Are we both talking about exim4 here? It is my understanding that the configuration file is automatically generated each time you run sudo dpkg-reconfigure exim4-config and I'm having trouble translating your hint above into something actionable in the set-up steps. – Tom Brossman Jun 2 '14 at 15:54
  • I don't use these configuration scripts, as they stop working once you want something a bit off the main path. – Stefan Schmiedl Jun 3 '14 at 12:09
  • I've downvoted your answer as I'm unable to 'guess' what to do with it and my twelve router files (I have searched through them - send_to_gateway: isn't there). If you have a complete answer and are withholding it for some reason, please go ahead and post it. Thanks for taking the time to type a reply but I'm afraid I have no clue what to do with it yet. – Tom Brossman Jun 3 '14 at 17:35
  • Thanks, I have this working finally. Are you using Ubuntu + exim4? I ask because he strings domainlist local_domains or send_to_gateway: do not exist in any of my routers. domains = ! +local_domains does though, and this was the clue I needed. I'll post what worked as a new answer to make it easier for noobs like me to figure it out... – Tom Brossman Jun 7 '14 at 14:21
  • First thing I did with exim4 on the debian box I had, was to get exim ignore the split files and use a single configuration file. Much easier to handle for humans :-) – Stefan Schmiedl Jun 9 '14 at 20:43
1

If you followed the guide linked in my question you have about a dozen different 'routers' (simple text files) in /etc/exim4/conf.d/router/. The one to edit is 200_exim4-config-primary, like so:

sudo nano /etc/exim4/conf.d/router/200_exim4-config_primary

Down the bottom is a section 'smarthost:' that looks like this:

smarthost:
  debug_print = "R: smarthost for $local_part@$domain"
  driver = manualroute
  domains = ! +local_domains
  transport = remote_smtp_smarthost
  route_list = * DCsmarthost byname
  host_find_failed = defer
  same_domain_copy_routing = yes
  no_more

Remove the exclamation point and a space from the 'domains' line so that it looks like this:

  domains = +local_domains

That two-character edit was all it took to get everything working just now. Tested and working with Google Apps at my domain on Ubuntu Server 12.04 + Exim & thanks to Stefan for the clue!

  • This solution didn't work for me at first. I had to add an MX record to my DNS at Digital Ocean to get the messages off the host. They just looped and froze before I added the record. – curt Feb 27 '15 at 2:46
1

Add your host to the dc_relay_domains config parameter like:

dc_relay_domains='example.com'

And remove ! sign before +local_domains in dnslookup_relay_to_domains from router/200_exim4-config_primary or exim4.conf.template if you don't use split configuration (dc_use_split_config='false') to looks like:

dnslookup_relay_to_domains:
  debug_print = "R: dnslookup_relay_to_domains for $local_part@$domain"
  driver = dnslookup
  domains = +local_domains : +relay_to_domains
  transport = remote_smtp
  same_domain_copy_routing = yes
  no_more

Or simply remove ! from dnslookup section to send everything outside:

dnslookup:
  debug_print = "R: dnslookup for $local_part@$domain"
  driver = dnslookup
  domains = +local_domains
  transport = remote_smtp
  same_domain_copy_routing = yes

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.