Re: Configuring Exim for mail delivery
On Fri, Sep 30, 2016 at 10:22:10PM +0200, mo wrote:
> Hi fellow Debian users ;)
> I want to do the following configuration:
> Send and deliver local mails between my systems. Currently exim is
> configured as a Internet Server (dpkg-reconfigure exim4-config).
> In general i kinda ask myself how i would go about doing that?
> I want to send mail from my server to my pc and vice versa, also i want to
> be able to send mail "out" to other smtp servers.
>
Depending on your local setup, having Exim set as an Internet server may
not be the right answer, as Liam has already said.
I'm going to make some assumptions here and you can correct them if they
are wrong.
I'll assume you have a home network and are trying to connect to send
mails between machines on that network, and additionally be able to send
email to domains outside your network.
I'm also assuming that you don't have specific domains for your own
machines, so that when you send mail outside you want to use an email
provider such as gmail, or hover, etc.
For most home network situations, ISPs don't like you trying to send
email directly from your home network. They want you to use their (or at
least SOMEONE's) smarthost. That makes it less likely they will find
themselves accessories to spamming. Also, many mainstream destination
email addresses will not accept mail from just any old place; if you try
to send mail directly to them from behind your home network router, even
if your ISP allows you to do so, the other end may reject the mail
because they can't tell what machine it is coming from.
If my assumptions above are right, you want to use "smarthost" as the
configuration. If I am wrong and you have your own domain and the right
to set up mail servers in it, then you do want the "internet" setting,
but you still want to pay attention to the rest of this message as it
addresses local network delivery.
I just figured out how to get this working myself a week or two back, so
it's fresh in my mind. The key trick is the use of "hubbed hosts".
Exim configuration has the concept of "routers" and "transports".
Routers basically decide what to do with a message, and transports do
it. One of the routers configured by default in the Debian exim
configuration is for "hubbed hosts". What this means, is machines
capable of sending and receiving email ("hosts" in exim speak) that are
on the same LAN as this machine (connected by a "hub"). Note that this
"hub" could be your local home network router, and for these purposes
machines on WiFi and machines on a wired LAN would be considered on the
same hub, even though that isn't strictly true. The point is that
network packets can be addressed directly between the machines, they
don't require a router in between.
In Debian, this is achieved with Avahi. This is what allows you, if you
have MachineA and MachineB on your network, to do for example "ping
MachineA.local" from MachineB and expect MachineA.local to be resolved
into an IP address.
As far as I can tell, Avahi is installed by default when you install a
new Debian installation. I don't know how long that has been true, but
my experience is that it is now.
In /etc/exim4, create a file owned by root called hubbed_hosts. In the
file, each line maps a "domain" (the part after the @ sign in an email
address) to a "host" (the name of a machine on your network, as it can
be reached from this machine). Put the domain first, then a tab
character (spaces may also be OK) and then the host. So for example I
have a machine on my network called affinity, and so in the hubbed_hosts
file on the machine I am sitting in front of now, I have two lines, one
saying "affinity.local<TAB>affinity.local", and the other saying
"affinity<TAB>affinity.local" (no quotes in the file). This tells the
local exim installation that any email address with @affinity.local as
the domain should be forwarded on to a machine called affinity.local,
and any mail with @affinity as the domain should be forwarded on to a
machine called affinity.local. Exim4 will then say "Connect to
affinity.local!" with no attempt to translate that into an IP address,
and Avahi daemon will answer "that is IP address WW.XX.YY.ZZ!" to which
exim will say "very well, connect to WW.XX.YY.ZZ!" and the exim4 on
affinity will wake up and co-operate to deliver the mail.
If the target email domain is not present in hubbed_hosts, then a
default "smarthost" configuration will fall through the hubbed hosts
router and arrive at the smarthost router, which in my case then tries
to use my mail provider to send a mail to a local machine, which is
doomed to failure because the outside provider cannot see my individual
machines on my local network.
If you really should be using the "internet" configuration, you still
need hubbed_hosts for local mails because whereas the hubbed_hosts
option just leaves it to the local network to figure out what it is
talking about, an internet-configured exim will attempt to find and send
to the target machine. To do so, it will send out a DNS request to
resolve the ip address of the target host. Avahi won't catch this, and
unless you are running a DNS server locally on your network (most people
don't, and many home network routers don't include one) that request
will go out of your network to the DNS server provided by your ISP. That
DNS server, being outside your network, won't be able to resolve your
local machine names and so won't be able to give you back an IP address
to use, unless your target machines are publicly individually visible on
the Internet, which is unlikely if this is a home configuration we are
talking about here.
So the configuration you are after is local domains specified in
hubbed_hosts, and everything else falls through to either a smarthost or
a dns-based attempt to send outside your network.
Hope that helps, let us know if you need more help.
Mark
Reply to: