Configuring Exim

As part of my scheme to setup the Debian machine, chrome, as the backup for the mail/web server, I had to grapple with exim, the MTA offered as default by Debian. This appeared a little simpler to configure than sendmail. To make exim run in the same manner as sendmail on crimson, the following configuration options were set (among many standard settings) in /etc/exim/exim.conf:

  # MAIN configuration
  
  qualify_domain = hydrus.org.uk
  local_domains = hydrus.org.uk:localhost
  
  # ROUTER Configuration
  
  smarthost:
  driver = domainlist
  transport = remote_smtp
  route_list = "* smtp.isp.com bydns_a"

These settings ensure that sender mail addresses were set as user@hydrus.org.uk and that my ISP's mail server was used to send all outgoing messages. You must also ensure that the fully qualified machine name is placed into /etc/hosts, either against 127.0.0.1 for machines where the IP is assigned via DHCP, or against the static IP assigned. The FQDN must be the first name specified. If this is not done, exim will refuse to accept mail for the machine, claiming it is being used as a relay.

At this point I thought about investigating whether I could persuade exim to handle the sending of mail to other machines in the domain. I had tried something similar before (see The Sendmail Saga), with only limited success. If the envelope was set to user@hydrus.org.uk, for mail sent to say, crimson, then the mail would (a) be rejected because the Alcatel router denied a domain of hydrus.org.uk existed, and (b) it would be impossible to reply to the mail as the information about the originating machine was not present. Setting the default qualify_domain to chrome.hydrus.org.uk will not work, as it is not possible to send mail outside of the domain, since the ISP's mail server will fail to find any DNS entries for chrome, and bounce the mail.

After a little experimentation, I found the following additions to the exim configuration file had the desired effect:

  # First, define a transport for local machines. This performs
  # rewriting of the envelope (return_path) and headers to 
  # indicate the mail is from chrome.
  
  local_smtp:
  driver = smtp
  return_path = ${local_part}@chrome.hydrus.org.uk
  headers_rewrite = *@hydrus.org.uk ${1}@chrome.hydrus.org.uk fr
  
  # In the ROUTES section, a new router is defined, which handles
  # recipient addresses on domain machines - anything ending in
  # the domain name, and unadorned host names (assuming they
  # contain no digits).  If the recipient does not match anything
  # in the domains value the smarthost router is used.
  
  local_network: 
  driver = lookuphost 
  transport = local_smtp
  domains = *.hydrus.org.uk:^[A-Za-z]*\$

This setup ensured that when mail was sent to a machine within the hydrus domain, the addresses were re-written to add chrome. The fully qualified machine name meant that the sendmail DNS lookups on the Alcatel router would return local IP addresses. Now, was it possible to get sendmail to handle things the same way?

I discovered later that a solution to this problem is in the Exim FAQ.