1

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.

Tom Brossman
  • 13,297

3 Answers3

2

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.

2

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!

Tom Brossman
  • 13,297
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
David Foerster
  • 36,890
  • 56
  • 97
  • 151
sedrakpc
  • 111