Exim4 LAN-relay on Debian Jessie with external smarthost

As part of a restructure at home I wanted to setup my router to be able to send email for all the servers on my LAN.
I tested it using Fastmail, but I know this will also work with Gmail. (I used the same setup when I had a gmail-account)

I did it like so:
:~# apt-get install exim4

:~# dpkg-reconfigure exim4-config

“Mail sent by smarthost; no local mail”

“System mail name: Home.Local”

IP-Address to listen on: Type in the LAN-IP of your router, or 0.0.0.0 if it’s entirely on a private/trusted LAN. (for example a standalone raspberry PI.)

“Other destinations for which mail is accepted: <leave blank>”

“Visible Domain name for local users: Home.Local”

IP-address or host name of the outgoing smarthost: This one depends on YOUR smarthost. Fastmail uses “mail.messagingengine.com::587”.

If you are lucky, you will get a prompt for, “Domains to relay mail for:” here, if that’s the case – Enter “*” and continue, otherwise we have to do something more.

Number-of-DNS-queries minimal, No.

Split configuration into small files, No.

If you were lucky, skip to configuring passwd.client, otherwise:

:~# editor /etc/exim4/update-exim4.conf.con
Fint and edit dc_relay_domains=” and add a *, so that it reads “dc_relay_domains=’*'”.
(Don’t just copy/paste that, quotes etc.)
Save the file, and re-run config to verify, then go ahead.

:~# editor /etc/exim4/passwd.client

And input using the following variables:
<servername>:<username>:<password>

For fastmail this equalls:
mail.messagingengine.com:leetuser@fastmail.com:leethax0rpassword
Save and restart exim using:

:~# systemctl restart exim4.service

Send a test-mail using:

:~# echo “testmail!” | mailx testmail@example.com

It should arrive!

Now for the clients in your LAN, the following should be done:

:~# apt-get install exim4

:~# dpkg-reconfigure exim4-config

“Mail sent by smarthost; no local mail”

“System mail name:” Leave as-is, should contain hostname+domain.

“IP-addresses to listen on for incoming SMTP connections:” Leave to something loopback-ish. (127.0.0.1, ::1)

“Other destinations for which mail is accepted:” Leave as-is.

“Visible domain name for local users:” Leave as-is.

“IP address or host name of the outgoing smarthost:” Enter the hostname/IP of the host created during the first part.

Number-of-DNS-queries minimal, No.

Split configuration into small files, No.

And then send a test-mail using the following command:

:~# echo “Testing mail via relay at <clock>” | mailx receiver@example.com

It can also be a good idea to update the mail-alias on the client.

:~# editor /etc/aliases

Replace the entry after root with a valid (and monitored) email, for example:
root: user+fileserver@example.com

Save the file, and you’re done.

Advertisements