Learn Linux Series (#5) - e-mail server (Exim)
poldek -i exim
Of course, before we execute the recommendation to start the daemon, we should make the configuration.
domainlist local_domains = @
The @ sign means 'my name'. To add additional domains, simply add them to this list separated by colons:
domainlist local_domains = @ : utopian.io : steemit.com : \
/etc/mail/local_domains
Besides utopian.io,steemit.com, Exim will now also accept domains listed in the /etc/mail/local_domains file. Domains should be entered in separate lines. Exim works so well that after adding a file path, you just need to reboot it once. Any combinations in /etc/mail/local_domains will not require a reboot. So it will be the most convenient to add to the configuration file:
domainlist local_domains = @ : /etc/mail/local_domains
And simply sign all domains to /etc/mail/local_domains
At this point, we can check the server's operation. All we need is to reload the daemon and send an email to the existing user account. With this configuration, the mail will reach the mbox mailboxes.
maildir_format = true
directory=${home}/Mail/Maildir
As you can easily guess, the second option indicates where the boxes are stored. After modification, the section discussed may look as follows:
local_delivery:
driver = appendfile
# file = /var/mail/$local_part
delivery_date_add
envelope_to_add
return_path_add
group = mail
mode = 0660
maildir_format = true
directory=${home}/Mail/Maildir
plain:
driver = plaintext
public_name = PLAIN
server_prompts = :
server_condition = ${if saslauthd{{$1}{$3}}{1}{0}}
# the above entry will work at saslauthd -a shadow, if
# we run saslauthd -a pam (eg. PLD) enter then:
# server_condition = ${if saslauthd{{$1}{$3}{smtp}}{1}{0}}
server_set_id = $2
login:
driver = plaintext
public_name = LOGIN
server_prompts = "Username:: : Password::"
server_condition = ${if saslauthd{{$1}{$2}}{1}{0}}
# the above entry will work at saslauthd -a shadow, if
# we run saslauthd -a pam (eg. PLD) enter then:
# server_condition = ${if saslauthd{{$1}{$3}{smtp}}{1}{0}}
server_set_id = $1
The last thing to do with saslauthd (run with the -a pam option) you need to create (or check if it is) is /etc/pam.d/smtp:
#%PAM-1.0
#
# example PAM file for saslauthd - place it as /etc/pam.d/
# (e.g. /etc/pam.d/smtp if you want to use saslauthd for SMTP
# AUTH)
#
auth required /lib/security/pam_listfile.so
item=user sense=deny file=/etc/security/blacklist
onerr=succeed
auth required /lib/security/pam_unix.so
auth required /lib/security/pam_tally.so
file=/var/log/faillog onerr=succeed no_magic_root
auth required /lib/security/pam_nologin.so
account required /lib/security/pam_tally.so deny=0
file=/var/log/faillog onerr=succeed no_magic_root
account required /lib/security/pam_unix.so
session required /lib/security/pam_unix.so
you must also run pwcheck saslauthd before checking the authorization
# echo 'pwcheck_method:saslauthd' > /etc/sasl/smtpd.conf
$ openssl genrsa -out /etc/mail/exim.key 1024
Generating RSA private key, 1024 bit long modulus
.......++++++
..............................++++++
e is 65537 (0x10001)
$ openssl req -new -x509 -days 365 -key /etc/mail/exim.key -out \
/etc/mail/exim.crt
Using configuration from /var/lib/openssl/openssl.cnf
You are about to be asked to enter information that will be
incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:EN
State or Province Name (full name) [Some-State]:NYC
Locality Name (eg, city) []:City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Utopian Ltd.
Organizational Unit Name (eg, section) []:Utopian's Mail Server
Common Name (eg, YOUR name) []:utopian.io
Email Address []:utopian@utopian.io
After such treatment, the following should be added to the Exim main section:
tls_certificate = /etc/mail/exim.crt
tls_privatekey = /etc/mail/exim.key
tls_advertise_hosts = *
after restart, Exim should be able to communicate with SSL without any problems, which can be seen in the logs:
U=exim P=esmtp X=TLSv1:DES-CBC3-SHA:168 S=2909
id=ebb601c374e2$80dace00$cab00a12@fv
Formerly, Exim could listen on port 465 only using inetd, in newer versions we will be able to set the appropriate options:
daemon_smtp_ports = 25 : 465
tls_on_connect_ports = 465
user_vacation:
driver = accept
check_local_user
# utopian-io is on vacation. We will try to write back as soon as possible.
condition = "${if or {{match {$h_precedence:} {(?i)junk|bulk|list}} {eq {$sender_address} {}}} {no} {yes}}"
no_expn
require_files = /var/mail/vacation/${local_part}/vacation.msg
# utopian-io is on vacation. We will try to write back as soon as possible.
senders = " ! ^.*-request@.*:\
! ^.*@list*.*:\
! ^owner-.*@.*:\
! ^postmaster@.*:\
! ^listmaster@.*:\
! ^mailer-daemon@.*\
! ^root@.*"
transport = vacation_reply
unseen
user = ${local_part}
no_verify
Next, we create a directory /var/mail/vacation, in which there will be directories containing the username and files with information about the reason for his absence. We write this reason to the vacation.msg file located in /var/mail/vacation/USER_NAME/. Once we have these settings behind us in the transport section, we add the following lines:
vacation_reply:
driver = autoreply
file = /var/mail/vacation/$local_part/vacation.msg
file_expand
from = System Automatycznej Odpowiedzi <$original_local_part@$original_domain>
log = /var/mail/vacation/$local_part/vacation.log
once = /var/mail/vacation/$local_part/vacation.db
once_repeat = 7d
subject = ${if def:h_Subject: {Re: ${quote:${escape:${length_50:$h_Subject:}}} (autoreply)} {Information} }
text = "\
Hi $h_from\n\n\
**your content**\n\
**your content2**:\n\
====================================================\n\n\
"
to = "$sender_address"
That's all, now we have to restart Exim:
# /etc/rc.d/init.d/exim restart
virtusertable_alias:
driver = redirect
allow_fail
allow_defer
data = ${lookup{$local_part@$domain}lsearch{/etc/mail/virtusertable}}
file_transport = address_file
pipe_transport = address_pipe
virtusertable_defaultalias:
driver = redirect
allow_fail
allow_defer
data = ${lookup{@$domain}lsearch{/etc/mail/virtusertable}}
file_transport = address_file
pipe_transport = address_pipe
Place the example above at the beginning of the routers section. For the record, let me add that the beginning of the section is marked with the word begin.
Below is a listing from the file /etc/mail/virtusertable
user@utopian.io user
user2@steemit.com user2
@domain.eu user3
User3 will receive all mail from the domain "domain.eu". After these procedures, exim should already be prepared to support multiple domains. You must remember to restart it after modifying its configuration file.
# /etc/rc.d/init.d/exim restart