Difference between revisions of "Exim with remote SMTP server"
(information about smarthost rewrite rules)
|Line 36:||Line 36:|
Revision as of 21:40, 5 August 2007
Use Exim with a remote smtp server
This document describes how to set up Exim (a mail transfer agent) to use a remote smtp server, for example your ISP's smtp server.
# pacman -S exim
/etc/mail/exim.conf and add or change the following
In Main Configuration Settings uncomment
primary_hostname and add the hostname of your box (see the
HOSTNAME field in
primary_hostname = myhostname # change to your hostname
At the end of the Routers Configuration section add
pass''on''to_isp: driver = manualroute domains = !+local_domains transport = remote_smtp route_list = * smtp.myisp.com # change to the desired smtp server
Make sure that in Transports Configuration it says (uncommented)
remote_smtp: driver = smtp
If you have a laptop, or a machine in a smarthost configuration, where you don't want the name of the machine to appear in the outgoing email then you must enable exim's rewriting facilities.
In the Rewriting section you should have something like:
where machine is the hostname of your laptop or PC and mydomain is the domain name of the machine and the outgoing mail.
FYI - I just got done wrestling with Exim (4.44) to get it up and running in this configuration on my machine, and I had to do a number of things quite differently than the other person. Thought I'd capture them here for posterity, since I had to go through a pretty painful process that cost me a lot of time and aggravation before I hit upon the right config. Hopefully this'll save others from a similar fate.
By the way, I should note: my Exim server does not receive any emails directly from the Net. I'm using fetchmail to grab the mail's from an external POP mail drop and dump them into my Exim server. So perhaps this is different than the other person's configuration.
Anyway, here's what worked for me.
I did not need to update
primary_hostname. If you leave it commented out, like this:
# primary_hostname =
then exim will just automatically use whatever your system's
hostname command outputs. (i.e., the
HOSTNAME that you've set in rc.conf.)
I very much DID need to update this line:
domainlist local_domains = @
and it caused me much grief until I got it right! In my case, it needed to look like this:
domainlist local_domains = @:localhost:mydnamicdnshostname.homeip.net
I think the dynamic dns entry might be optional (since I never really deliver any mail to an address at that FQDN), but the
@ and the
localhost are both critical.
@basically means again to use whatever your system's
hostnamecommand outputs. That's needed because some daemons that run on your box may try to send emails to the root user at the host, and they will get rejected if you don't have the
localhostwas necessary in order to allow fetchmail to deliver all the messages that it fetched. Without that entry there, Exim would fail to deliver them, and then generate a bounce message in response. Even worse, most of my fetched messages were spam, and so it would try to send the bounce back to the return address on the spam which 1) often was forged, and thus a bad thing to do, and 2) often would get rejected either due to an invalid email address or because I was trying to initiate email from a residential dynamic IP address and thus was also a bad thing to do. In the latter case, those messages wound up frozen on the queue, and I had to spend some time manually purging them from the queue. Just a bad situation all around until I got this piece right.
- I also wanted to allow other boxes on my LAN to relay messages through this exim server. By default, though, that's blocked. You can enable it by changing this:
hostlist relay''from''hosts = 127.0.0.1
hostlist relay''from''hosts = 127.0.0.1 : 192.168.0.0/24
While, you're at it, it actually couldn't hurt to make it this:
hostlist relay''from''hosts = 127.0.0.1 : ::::1 : 192.168.0.0/24
::::1 is just the ipv6 equivalent of 127.0.0.1)
Despite what was written by the other person, I found that that the
passonto_isp router should NOT go at the end of the Routers Configuration section. Since it's at the end, it won't get executed if some other router gets executed first, and that's exactly what was happening to me. This router, which appears before it was getting executed instead:
dnslookup: driver = dnslookup domains = ! +local_domains transport = remote_smtp ignore''target''hosts = 0.0.0.0 : 127.0.0.0/8 no_more
That router might be desired in some configurations, but not this one. That will cause exim to try to deliver the message itself, rather than passing it on to your ISP's MTA. (And as I indicated above, that will often fail if you're on a residential dynamic IP adddress.) To set this up properly, do it like this:
#dnslookup: # driver = dnslookup # domains = ! +local_domains # transport = remote_smtp # ignore''target''hosts = 0.0.0.0 : 127.0.0.0/8 # no_more pass''on''to_isp: driver = manualroute domains = !+local_domains transport = remote_smtp route_list = * smtp.myisp.com # change to the desired smtp server
One last thing: make sure to also update the
/etc/mail/aliases file, if you've got any daemons running on your box that need to send email to the root user. You'll probably want those emails to get delivered to your non-root user account instead, and this is how you set that behavior. Look for these lines:
# Person who should get root's mail #root:
And uncomment and add your local user account to the
# Person who should get root's mail root: johndoe
Hope this all spares someone some hair-pulling and lost sleep down the road. I wish I had read an entry like this before I started - I wouldn't be so tired right now!