Translation(s): English - Italiano - Português (Brasil)
Contents
- Exim Overview
- Installation and Basic Configuration
- Configuration Files
-
Things you might want to configure
- TLS and authentication
- SPF filtering
- DKIM
- DNS Blacklists
- Email sub-addressing (plus-signs as in Gmail)
- Install diagnostic tools
- User authentication
- Spam scanning
- Exim access control lists (ACLs)
- Smarthost with Authentication
- Running solely as Debian-exim user for increased security
- DMARC Support
- For running a mailing list and ensuring all sent mail is DMARC compliant
- Exim local mail testing/development
- See also
Exim Overview
Exim is a message transfer agent (MTA).
Installation and Basic Configuration
exim4-daemon-light usually comes installed on Debian by default. For advanced features such as:
- LDAP;
- sqlite, PostgreSQL and MySQL data lookups;
- SASL and SPA SMTP authentication;
- embedded Perl interpreter; and
- the content scanning extension (formerly known as "exiscan-acl") for virus scanner and spamassassin
you probably need to install exim4-daemon-heavy.
/usr/share/doc/exim4-config/README.Debian.gz, included in exim4-config, details Debian-style configuration specific to the package version.
When installing Exim 4, debconf asks basic configuration questions. debconf saves your answers in /etc/exim4/update-exim4.conf.conf [sic]. You can run the same configuration process later by invoking:
# dpkg-reconfigure exim4-config
Although Debian extends the default configuration from upstream, by design it only handles basic configuration. Manual file editing will probably be necessary to do things that the debconf-driven process does not handle.
Example debconf-generated macro file
If you do not know how to answer debconf's questions, this tested configuration should be suitable for internal use:
# dpkg-reconfigure exim4-config
1 General type of mail configuration: internet site; mail is sent and received directly using SMTP.
2 System mail name: yourdomain.com
3 IP-addresses to listen on for incoming SMTP connections: # leave blank
4 Other destinations for which mail is accepted: yourdomain.com
5 Domains to relay mail for: # leave blank
6 Machines to relay mail for: # leave blank
7 Keep number of DNS-queries minimal (Dial-on-Demand)?: No
8 Delivery method for local mail: Maildir format in home directory
9 Split configuration into small files? : No
This saves to /etc/exim4/update-exim4.conf.conf. update-exim4.conf has the complete list of settings that go into /etc/exim4/update-exim4.conf.conf. When finished, generate the Exim configuration by invoking:
# update-exim4.conf
This parses the configuration file(s) together and saves the result to /var/lib/exim4/config.autogenerated. Avoid editing this file yourself!
Then restart Exim with:
# systemctl restart exim4
or
# service exim4 restart
Configuration Files
Debian's Exim 4 package provides several methods to simplify configuration. The subsections below summarize Exim's configuration options, which debconf asks during installation or reconfiguration ("Split configuration into small files?").
Single monolithic configuration file
Answering "No" creates a single /etc/exim4/exim4.conf.template file.
The default file lets you select and configure many features by setting values for various macros. /etc/exim4/exim4.conf.localmacros is the ideal place to put macros you want to set because Exim reads it first. However, you must create this file yourself because the Debian packages do not provide it. This lets you control features, like DKIM, without editing the Debian-provided files. Better still, package upgrades will not overwrite this file.
Split configuration files
Answering "Yes" creates /etc/exim4/conf.d/ and populates it with smaller configuration files.
Each section of the configuration file has its own subdirectory, which update-exim4.conf concatenates together in alphabetical order. This lets you insert custom configuration files by naming them by how you want them to appear alphabetically. For example, naming a file 00_exim4-my-config makes update-exim4.conf parse it pretty much first. The other advantage is that your additions will stay untouched relative to its neighbors between package upgrades.
Your own configuration file
A single file is probably best for in complex setups with lots of customizations.
Simply install your own file in /etc/exim/exim4.conf and exim will use that file verbatim.
To have something to start with, you can either take /etc/exim4/exim4.conf.template, run update-exim4.conf --keepcomments --output /etc/exim4/exim4.conf, or use upstream's default configuration file that is installed as /usr/share/doc/exim4-base/examples/example.conf.
If you want to avoid the macro cruft use /usr/share/doc/exim4-base/examples/example.conf Simply rename it exim4.conf and place it in /etc/exim4/
Using /etc/exim4/exim4.conf will disable the functions of debconf though, so expect to become familiar with Exim to build a working config. (documentation is found at https://dev.exim.org/docs.html )
Note that /etc/exim4/exim4.conf is read directly by Exim 4 every time the exim binary forks. If you edit the configuration in place, each SMTP connection will read a different configuration file!
Things you might want to configure
TLS and authentication
Generating a local certificate
Generate a certificate using:
# bash /usr/share/doc/exim4-base/examples/exim-gencert
It will generate exim.crt and exim.key in /etc/exim4/
Instead of generating a certificate, you may simply copy certificates that you have purchased or generated previously.
Dual stack RSA/ECDSA configuration
If you wish to support both ECDSA and RSA algorithms, you can provide more than one certificate:
tls_certificate = /etc/exim4/exim_ecdsa.crt : /etc/exim4/exim_rsa.crt tls_privatekey = /etc/exim4/exim_ecdsa.key : /etc/exim4/exim_rsa.key
Exim will select a certificate to present to the client based on the selected cipher. The priority order for ciphers will affect which certificate is used.
Enable TLS
Edit /etc/exim4/exim4.conf.localmacros and add the following line:
MAIN_TLS_ENABLE = yes
This, of course, may be already enabled in the main configuration template "exim4.conf.template"
As with any change to the configuration, run update-exim4.conf then restart exim: service exim4 restart
Communicating with a smarthost
If, like most home users, you are not actually running an Internet server but instead are using e-mail accounts from an ISP or other company (e.g. gmail, hotmail, yahoo mail, etc.), you will need to communicate with their smtp server to send mail.
Every company seems to configure their server differently and puts different restrictions on how you can send mail. This makes configuring Exim4 difficult to describe as a general case. Adding tls makes things even more complicated. However you should always use tls (if available) so that your login is sent encrypted and not as plain text.
I'm going to describe a setup that should work in most cases when you are sending mail using a single account to a single smarthost.
- Select one of the smarthost options when running dpkg-reconfigure exim4-config. When specifying the smarthost, include both the smarthost server name and the port it wants you to use (e.g. example.com::465). Note the double colons.
- Add authentication credentials for a specific server to /etc/exim4/passwd.client:
<server>:<username>:<user password> (e.g. server.example.com:mymail@example.com:abdc1243)
or specify credentials for every server:
*:<username>:<user password> (e.g. *:mymail@example.com:abdc1243)
- Add the following lines to /etc/exim4/exim4.conf.localmacros (you may need to create it if it doesn't exist):
MAIN_TLS_ENABLE = 1 REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS = * TLS_ON_CONNECT_PORTS = 465 REQUIRE_PROTOCOL = smtps
Add the following to /etc/exim4/exim4.conf.template after .ifdef REMOTE_SMTP_SMARTHOST_HOSTS_REQUIRE_TLS ... .endif
.ifdef REQUIRE_PROTOCOL protocol = REQUIRE_PROTOCOL .endifAdd the following after .ifdef MAIN_TLS_ENABLE
.ifdef TLS_ON_CONNECT_PORTS tls_on_connect_ports = TLS_ON_CONNECT_PORTS .endif- The SMTP server may reject mail without a proper ""From:"" address. Add a line to /etc/email-addresses to link each linux user to an email address e.g.
root:sysadmin@example.org
Run update-exim4.conf followed by service exim4 restart
SPF filtering
This is provided via the macro CHECK_RCPT_SPF, set it to true.
For Debian-exim package prior to Debian 12 (bookworm), Exim uses a helper tool, which you will need to install:
# apt install spf-tools-perl
You should then run update-exim4.conf and restart exim.
DKIM
this part is work in progress
There are several keys:
dkim_canon='relaxed'
dkim_selector='default'
dkim_domain='${sender_address_domain}'dkim_private_key='/etc/exim4/keys/dkim_ed25519.private'
dkim_sign_headers='from:to:cc:in-reply-to:subject:date:message-id'
DNS Blacklists
You can configure exim to use DNS Blacklists to block IP with the macro CHECK_RCPT_IP_DNSBLS :
CHECK_RCPT_IP_DNSBLS=zen.spamhaus.org
You can also configure exim to use DNS Blacklists to block domain with the macro CHECK_RCPT_DOMAIN_DNSBLS, exemple :
CHECK_RCPT_DOMAIN_DNSBLS=<key>.dbl.dq.spamhaus.net
The default behaviour is not to block the hosts found in the lists, but just add a warning header. In order to truly blacklist the spammers, just change 'warn' by 'deny' in the following block:
.ifdef CHECK_RCPT_IP_DNSBLS
warn # <--- deny
dnslists = CHECK_RCPT_IP_DNSBLS
add_header = X-Warning: $sender_host_address is listed at $dnslist_domain ($dnslist_value: $dnslist_text)
log_message = $sender_host_address is listed at $dnslist_domain ($dnslist_value: $dnslist_text)
.endifThen restart exim.
Email sub-addressing (plus-signs as in Gmail)
These can easily be achieved by adding something similar to the following in one of more of your router definitions
local_part_suffix = +* : -* : _* local_part_suffix_optional
The above example would deliver user+example@domain.com, user-example@domain.com and user_example@domain.com to user@domain.com.
Similarly, you could use a prefix instead with these similarly named options
local_part_prefix = *+ : *- : *_ local_part_prefix_optional
The above example would deliver example+user@domain.com, example-user@domain.com and example_user@domain.com to user@domain.com.
In either case, you could then use sieve filtering, config tricks or your email client to apply delivery rules.
Install diagnostic tools
#apt install swaks libnet-ssleay-perl
Test the connection:
$swaks -a -tls -q HELO -s localhost -au your_user -ap '<>' === Trying localhost:25... === Connected to localhost. <- 220 debianwb ESMTP Exim 4.76 Thu, 04 Aug 2011 14:22:02 +0600 -> EHLO debianwb <- 250-debianwb Hello localhost [127.0.0.1] <- 250-SIZE 52428800 <- 250-PIPELINING <- 250-STARTTLS <- 250 HELP -> STARTTLS <- 220 TLS go ahead === TLS started w/ cipher DHE-RSA-AES256-SHA ~> EHLO debianwb <~ 250-debianwb Hello localhost [127.0.0.1] <~ 250-SIZE 52428800 <~ 250-PIPELINING <~ 250 HELP ~> QUIT <~ 221 evie closing connection
Note that above we are sending an empty password while testing with the swaks tool.
Some ISPs may block connecting to port 25, and also some broken clients insist TLS on Port 465.
To support these, change /etc/default/exim4 as:
SMTPLISTENEROPTIONS='-oX 465:25 -oP /var/run/exim4/exim.pid'
Also edit /etc/exim4/exim4.conf.template:
##################################################### ### main/03_exim4-config_tlsoptions ##################################################### tls_on_connect_ports=465 ### main/03_exim4-config_tlsoptions #################################
Check the already mentioned README.Debian.gz file for details.
User authentication
Adding user authentication is possible using tools like Dovecot or sasl2-bin. For shell users who would like to use SASL and PAM for password authentication, that can setup this way:
# apt install sasl2-bin
Edit /etc/default/saslauthd to enable saslauth:
START=yes
Start the deamon:
# service saslauthd start
In /etc/exim4/exim4.conf.template, uncomment the following lines to enable authentication via saslauthd:
plain_saslauthd_server:
driver = plaintext
public_name = PLAIN
server_condition = ${if saslauthd{{$auth2}{$auth3}}{1}{0}}
server_set_id = $auth2
server_prompts = :
.ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
.endifAdd exim to the sasl group:
# adduser Debian-exim sasl
In Debian 12, if you find exim error like - "cannot connect to saslauthd daemon at /var/run/saslauthd/mux: No such file or directory".
You may try to set authentication mechanism which will create missing /var/run/saslauthd/mux
-a <authmech> Selects the authentication mechanism to use. authentication mechanisms: sasldb getpwent kerberos5 pam rimap shadow ldap # saslauthd -a pam
Restart exim:
# service exim4 restart
Test the connection using your username:
# swaks -a -tls -q AUTH -s localhost -au your_user Password:
Enable IMAP access by installing Courier-Imap or a similar MTA.
Spam scanning
There are several ways to detect spam.
Exim has default configuration for spamassassin (exim4-daemon-heavy required).
# apt install spamassassin
If you are using Debian Jessie or later (with systemd enabled by default), enable and start the service using systemctl;
# systemctl enable spamassassin.service
On earlier Debian releases, edit /etc/default/spamassassin ...
ENABLED=1
...and then start the daemon.
# service spamassassin start
On all systems, edit /etc/exim4/exim4.conf.template as required for your system.
First, if necessary, set the spamd_address:
# For spam scanning, there is a similar option that defines the interface to # SpamAssassin. You do not need to set this if you are using the default, which # is shown in this commented example. As for virus scanning, you must also # modify the acl_check_data access control list to enable spam scanning. spamd_address = 127.0.0.1 783
Next, edit the acl_check_data section to add suitable spam headers:
### acl/40_exim4-config_check_data
#################################
# This ACL is used after the contents of a message have been received. This
# is the ACL in which you can test a message's headers or body, and in
# particular, this is where you can invoke external virus or spam scanners.
acl_check_data:
...
...
...
# See the exim docs and the exim wiki for more suitable examples.
#
# warn
# spam = Debian-exim:true
# add_header = X-Spam_score: $spam_score\n\
# X-Spam_score_int: $spam_score_int\n\
# X-Spam_bar: $spam_bar\n\
# X-Spam_report: $spam_report
# put headers in all messages (no matter if spam or not)
warn spam = debian-spamd:true
add_header = X-Spam-Score: $spam_score ($spam_bar)
add_header = X-Spam-Report: $spam_report
# add second subject line with *SPAM* marker when message
# is over threshold
warn spam = debian-spamd
add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:Note that the above configuration also adds an X-Spam-Report header in outgoing emails, thereby violating RFC2822. Some mail servers, in particular the Debian mailing-list server, simply drop such non-conformant emails. See also Debian bug 774553.
For more information about configuring spam filters, see the exim documentation.
To test your spamassassin setup follow spamassassin https://wiki.apache.org/spamassassin/TestingInstallation and gtube.
Exim access control lists (ACLs)
Exim provides flexible way to set access control list. For detailed information, see the ACL documentation on the exim wiki.
For example, if we are trying to deny all mail from three free email service providers (domain1.com, domain2.com, domain3.com) based on Received headers from the servers, we can use the following lines:
deny
condition = ${if match{$h_Received:}{\N\.(domain1|domain2|domain3)\.com\N}{yes}{no}}
message = This mailbox does not support free e-mail services.
Smarthost with Authentication
Start by reconfiguring exim4:
sudo dpkg-reconfigure exim4-config
Select mail sent by smarthost, no local mail (unless you are configuring local mail, which most folks at home do not need).
Then edit the file:
sudo vim /etc/exim4/passwd.client
And add the line:
*:login:password
Substituting the correct email account login name for login and corresponding password. Comments in the passwd.client file will provide additional information about configuration options.
Most ISPs offer multiple email accounts so it may make sense security wise to create an account just for utility use such as this. If your Linux host is ever compromised you will be glad you had a separate utility email account.
NOTE: you should also see the section https://wiki.debian.org/Exim#TLS_and_authentication (above) about configuring tls. You should never communicate with a smarthost without an encrypted connection.
Running solely as Debian-exim user for increased security
This will avoid setuid elevation to root, which was exploited in a security bug in the past.
/etc/systemd/system/exim4.service.d/nonroot.conf
[Service] # see 56.2 Root privilege in exim spec AmbientCapabilities=CAP_NET_BIND_SERVICE
chown Debian-exim:Debian-exim /usr/sbin/exim4 # needs guid set in order to become Debian-exim chmod g+s,u+s /usr/sbin/exim4
Ensure that your exim is setup to route all mail before it gets to 300_exim4-config_real_local in routers.
These related hardening systemd options seem to work fine too:
[Service] PrivateTmp=yes ProtectHome=yes NoNewPrivileges=yes ProtectSystem=yes
DMARC Support
Note Trisquel 8 backports repository, exim4-daemon-heavy has DMARC support builtin, and is based on the version from ubuntu 18.04.
You will need to compile a modified version of exim, editing any of the EDITME configuration files in a patch like the one below. In your configuration, you will need to use the spf builtin to exim instead of the external one that Debian's default config ships with. Documentation of these features is in https://github.com/Exim/exim/blob/master/doc/doc-txt/experimental-spec.txt
@@ -459,9 +462,9 @@ # installed on your system (www.libspf2.org). Depending on where it is installed # you may have to edit the CFLAGS and LDFLAGS lines. -# EXPERIMENTAL_SPF=yes -# CFLAGS += -I/usr/local/include -# LDFLAGS += -lspf2 +EXPERIMENTAL_SPF=yes +CFLAGS += -I/usr/local/include +LDFLAGS += -lspf2 # Uncomment the following lines to add SRS (Sender rewriting scheme) support. # You need to have libsrs_alt installed on your system (srs.mirtol.com). @@ -474,10 +477,10 @@ # Uncomment the following line to add DMARC checking capability, implemented # using libopendmarc libraries. You must have SPF support enabled also. -# EXPERIMENTAL_DMARC=yes -# DMARC_TLD_FILE= /etc/exim/opendmarc.tlds -# CFLAGS += -I/usr/local/include -# LDFLAGS += -lopendmarc +EXPERIMENTAL_DMARC=yes +DMARC_TLD_FILE= /etc/exim4/opendmarc.tlds +CFLAGS += -I/usr/local/include +LDFLAGS += -lopendmarc # Uncomment the following lines to add Brightmail AntiSpam support. You need # to have the Brightmail client SDK installed. Please check the experimental
Exim will also have new dependencies, libopendmarc2 and libspf2-2. And their dev version for building.
For running a mailing list and ensuring all sent mail is DMARC compliant
Mailman lists can easily be misconfigured to send out DMARC failing messages. If configured properly, it will not modify DKIM signatures, and send DMARC compliant mail without "munge from" set.
However sometimes people misconfigure exim by using the default DKIM headers, which includes List-* headers, which sets up Mailman to send DMARC failing messages because it needs to modify them. Exim can do from munging in this case. This also allows Mailman lists to have content filtering turned on, and rely on exim to munge from when it happens, since Mailman isn't smart enough to only munge in that case.
Exim local mail testing/development
By default Exim disable local mail delivery
- /etc/exim4/exim4.conf.template
dnslookup:
debug_print = "R: dnslookup for $local_part@$domain"
driver = dnslookup
domains = ! +local_domains
transport = remote_smtp
same_domain_copy_routing = yes
# ignore private rfc1918 and APIPA addresses
ignore_target_hosts = 0.0.0.0 : 127.0.0.0/8 : 192.168.0.0/16 :\
172.16.0.0/12 : 10.0.0.0/8 : 169.254.0.0/16 :\
255.255.255.255
no_more
.endifYou need to remove local IP series of your testing/development environment.
Related pages:
See also
