How to install Exim4 on a local (LAN) host to use an SMTP smarthost for sending mail

First of all: install exim Smile
apt-get install exim4 bsd-mailx
Now we have to reconfigure it, because by default it won't deliver any mails to any external address:
dpkg-reconfigure exim4-config

Assuming your host on your LAN is myhost.local, your email domain (the one that you have valid email-addresses in) is example.com and the smarthost of your choice is smtp.myisp.com, answer the questions like this:
  • General type of mail configuration: mail sent by smarthost; no local mail
  • System mail name: myhost.local
  • IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1
  • Other destinations for which mail is accepted: (leave this one empty)
  • Visible domain name for local users: example.com
  • IP address or host name of the outgoing smarthost: smtp.myisp.com
  • Keep number of DNS-queries minimal (Dial-on-Demand)? No
  • Split configuration into small files? No
You usually will want to forward emails of local users of this host (eg. root) to another address (eg. lan-root@example.com), so add it to the /etc/aliases file like this:
root: lan-root@example.com

Now test the setup by sending email to both an external address and a local user (eg. root):
d="$(date)"; echo "Now is: $d" | mailx -v -s "Test ($d)" myuser@example.com
d="$(date)"; echo "Now is: $d" | mailx -v -s "Test ($d)" root

If both mails arrived (the second one to lan-root@example.com), you're all set.

P.S.: if you get "sender address rejected: domain not found" errors while sending the test emails, you most probably specified a bad domain name in the answer to the question "Visible domain name for local users". Exim4 uses the value specified here in the MAIL FROM: SMTP command while talking to the smarthost. And nowadays most smarthosts will verify (using a DNS lookup) that this contains a valid/public domain. Since your host is sitting on a LAN, this check will fail if you specified the host's fqdn here.