SMTP – How to Resolve Unroutable Address Issues

emaileximg-suitesmtp

I have set up gmail google app accounts for our own domain, domain.com, so that email is handled by gmail. I.e. MX records point to google servers, A records to our own server IP. This works fine.

Now I tried sending emails from our machine (via crontab, using Debian's exim4) to our own email address, e.g. admin@domain.com.

This doesn't work. Presumably exim is seeing the address as local and fails to forward it to the google servers. The delivery fails with:

Subject: Mail delivery failed: returning message to sender

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  admin@domain.com
    Unrouteable address

and is then unhelpfully delivered to /var/mail.

Emails to other addresses — outside of domain.com — work ok.

I looked at the configs under /etc/exim4/conf.d/ but couldn't make sense of it.

Any help is welcome. Cheers!

Best Answer

I solved the problem by creating a new router, inside the .ifdef DCconfig_internet block:

my_domain:
  debug_print = "R: dnslookup for $local_part@$domain"
  driver = dnslookup
  domains = domain.com
  transport = remote_smtp
  # ignore private rfc1918 and APIPA addresses
  ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8 : 192.168.0.0/16 :\
                        172.16.0.0/12 : 10.0.0.0/8 : 169.254.0.0/16 :\
                        255.255.255.255
  no_more

This forces a remote delivery (via standard dnslookup) even for *@domain.com addresses, which is exactly what I wanted.

There may be an easier way to achieve this, by modifying the existing routers, but this "works for me".