<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.bgzashtita.es/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=31.221.0.0%2F16</id>
	<title>Bgzashtita Official wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bgzashtita.es/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=31.221.0.0%2F16"/>
	<link rel="alternate" type="text/html" href="https://wiki.bgzashtita.es/index.php?title=Special:Contributions/31.221.0.0/16"/>
	<updated>2026-11-20T11:10:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://wiki.bgzashtita.es/index.php?title=Linux/manual&amp;diff=26</id>
		<title>Linux/manual</title>
		<link rel="alternate" type="text/html" href="https://wiki.bgzashtita.es/index.php?title=Linux/manual&amp;diff=26"/>
		<updated>2023-07-25T03:04:37Z</updated>

		<summary type="html">&lt;p&gt;31.221.221.92: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;sudo du -hsx / | sort -rh | head -20&amp;quot;&lt;br /&gt;
&lt;br /&gt;
What&#039;s the output of `df -h | nc termbin.com 9999` ?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And this? sudo du -sh /var /usr /lib&lt;br /&gt;
&lt;br /&gt;
du -sh /lib /home ==&amp;gt; check both lib and home as well&lt;br /&gt;
&lt;br /&gt;
Your /var is a bit big too, maybe log is a lot; try: du -sh /var/* | sort -h&lt;br /&gt;
&lt;br /&gt;
You may continue with `sudo du -sh /var/lib/* | sort -h` if you wish to pinpoint it&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
how to purge and install efi:&lt;br /&gt;
&lt;br /&gt;
Okay, let&#039;s walk through the full steps start to finish to get your system booting properly again:&lt;br /&gt;
&lt;br /&gt;
Boot from a Debian live USB/CD in UEFI mode.&lt;br /&gt;
&lt;br /&gt;
Use fdisk or gdisk to verify your partition table - make sure you have partitions setup for EFI, root, and any others needed.&lt;br /&gt;
&lt;br /&gt;
Format the EFI partition as FAT32 if needed.&lt;br /&gt;
&lt;br /&gt;
Mount the root and EFI partitions:&lt;br /&gt;
&lt;br /&gt;
mount /dev/nvme0n1p2 /mnt   # Root partition&lt;br /&gt;
mount /dev/nvme0n1p1 /mnt/boot/efi # EFI partition&lt;br /&gt;
Chroot into the mounted root partition:&lt;br /&gt;
chroot /mnt /bin/bash&lt;br /&gt;
Install the GRUB and Linux packages:&lt;br /&gt;
apt update&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
apt install grub-efi-amd64 grub-common linux-image-amd64&lt;br /&gt;
Generate an initramfs image:&lt;br /&gt;
update-initramfs -c -k all&lt;br /&gt;
Verify the kernel and initrd files now exist in /boot&lt;br /&gt;
&lt;br /&gt;
Edit /etc/fstab to match partitions if needed.&lt;br /&gt;
&lt;br /&gt;
Generate a GRUB config file and reinstall GRUB:&lt;br /&gt;
&lt;br /&gt;
grub-mkconfig -o /boot/grub/grub.cfg&lt;br /&gt;
grub-install&lt;br /&gt;
update-grub&lt;br /&gt;
Reboot and verify you can boot into GRUB and then Linux!&lt;br /&gt;
Let&#039;s take it step-by-step. Let me know if you get stuck or have any errors at any point in the process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pissed: with every new version ubuntu IS SHIT:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So on ubuntu 23.04 there is pain in all body, as they change ip static changes: It is not like classic unknown where put code, it is in yaml and it use netplan, not restarting networwking. So here is config:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 nano /etc/netplan/00-installer-config.yaml                                                  &lt;br /&gt;
&lt;br /&gt;
# This is the network config written by &#039;subiquity&#039;&lt;br /&gt;
network:&lt;br /&gt;
  ethernets:&lt;br /&gt;
        ens160:&lt;br /&gt;
            addresses: [&#039;192.168.3.237/24&#039;]&lt;br /&gt;
            gateway4: 192.168.3.1&lt;br /&gt;
            nameservers:&lt;br /&gt;
                addresses: [192.168.3.1, 8.8.4.4, 8.8.8.8]&lt;br /&gt;
                search: [localdomain]&lt;br /&gt;
  version: 2&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After safe and exit&lt;br /&gt;
&lt;br /&gt;
Now here is SHIT CATCH:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
to apply for getting ip:&lt;br /&gt;
&lt;br /&gt;
get admin rights and write:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 netplan apply&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
now you have internet:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-----------------------------------------------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
managed-keys-zone: Key 20326 for zone . is now trusted (acceptance timer complete)&lt;br /&gt;
2023-07-25T00:11:45.272385+00:00 ns1 named[39807]: managed-keys.bind.jnl: open: permission denied&lt;br /&gt;
2023-07-25T00:11:45.272407+00:00 ns1 named[39807]: managed-keys-zone: keyfetch_done:dns_journal_open -&amp;gt; unexpected error&lt;br /&gt;
2023-07-25T00:11:45.272428+00:00 ns1 named[39807]: managed-keys-zone: error during managed-keys processing (unexpected error): DNSSEC validati&lt;br /&gt;
&lt;br /&gt;
this is solution for ubuntu and debian&lt;br /&gt;
&lt;br /&gt;
 sudo chown -R root:bind  /var/cache/bind&lt;br /&gt;
 sudo chown -R root:bind  /var/cache/bind/managed-keys.bind&lt;br /&gt;
 sudo chown -R root:bind  /var/cache/bind/managed-keys.bind.jnl&lt;/div&gt;</summary>
		<author><name>31.221.221.92</name></author>
	</entry>
	<entry>
		<id>https://wiki.bgzashtita.es/index.php?title=Mail_server_english&amp;diff=9</id>
		<title>Mail server english</title>
		<link rel="alternate" type="text/html" href="https://wiki.bgzashtita.es/index.php?title=Mail_server_english&amp;diff=9"/>
		<updated>2023-03-19T03:46:03Z</updated>

		<summary type="html">&lt;p&gt;31.221.135.161: Created page with &amp;quot;  Own mail server based on Dovecot, Postfix, MySQL, Rspamd and Debian 9 Stretch   This how-to is based on my previous German how-to for Ubuntu 16.04 Server. Instead of using Spamassassin, Amavis, Pyzor and Razor as well es OpenDKIM, we’ll make use of Rspamd. Rspamd as a modern replacement will reduce the complexity of our setup and let us monitor its state via a web interface. As in earlier versions of my mailserver how-to, I’ll explain most important parts of the sy...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
Own mail server based on Dovecot, Postfix, MySQL, Rspamd and Debian 9 Stretch&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This how-to is based on my previous German how-to for Ubuntu 16.04 Server. Instead of using Spamassassin, Amavis, Pyzor and Razor as well es OpenDKIM, we’ll make use of Rspamd. Rspamd as a modern replacement will reduce the complexity of our setup and let us monitor its state via a web interface. As in earlier versions of my mailserver how-to, I’ll explain most important parts of the system as we install and configure them one after another. You will need basic Linux and command line knowledge to finish this guide. Going through this article will take probably about 45 minutes - depending on your speed and skills.&lt;br /&gt;
If you’d rather like to use a simple Docker setup, have a look at Mailcow by André Peters.&lt;br /&gt;
Mail server features&lt;br /&gt;
&lt;br /&gt;
To get a basic idea of what this mail server will be capable of:&lt;br /&gt;
&lt;br /&gt;
    Sending and receiving e-mails for various domains of your choice&lt;br /&gt;
    Adding and removing domains, accounts, aliases, redirects and TLS policies via a MySQL DB backend&lt;br /&gt;
    Per-user mailbox quota&lt;br /&gt;
    Global and user-specific sieve rules&lt;br /&gt;
    High performance spam server detection via postscreen&lt;br /&gt;
    Extended spam message detection via Rspamd (+ web interface for spam stats)&lt;br /&gt;
    “Send only” accounts e.g. for NextCloud / blog software / …&lt;br /&gt;
    DKIM-signing for outbound e-mails&lt;br /&gt;
&lt;br /&gt;
Please note: There is no “official” management- / web interface for mailbox management, but some users implemented their own mailbox account management software for this setup:&lt;br /&gt;
&lt;br /&gt;
    Florian Kapfenberger: Mailman (not to be confused with Mailman, the mailing list Mmnager!)&lt;br /&gt;
    Andreas Bresch: VmailManage&lt;br /&gt;
    Henrik Halbritter: MailAdmin&lt;br /&gt;
    awidegreen: vmail-rs (CLI tool!)&lt;br /&gt;
    pprugger: vmail-admin&lt;br /&gt;
    Kekskurse: Go-Mail-Admin&lt;br /&gt;
&lt;br /&gt;
Rspamd Webinterface&lt;br /&gt;
Rspamd Webinterface&lt;br /&gt;
Software for this setup&lt;br /&gt;
&lt;br /&gt;
    Debian 9 “Stretch”&lt;br /&gt;
    Postfix&lt;br /&gt;
    Dovecot&lt;br /&gt;
    Rspamd&lt;br /&gt;
    Redis&lt;br /&gt;
    MariaDB&lt;br /&gt;
    Nginx (optional)&lt;br /&gt;
&lt;br /&gt;
This setup is not fully compatible with Ubuntu Server by default, since Ubuntu is currently shipped with older Versions of Dovecot, with e.g. do not support imap_sieve! To still use this guide for Ubuntu Server, you have to get a newer version of Dovecot, e.g. by adding this PPA to your system: https://launchpad.net/%7Epdoes/+archive/ubuntu/dovecot&lt;br /&gt;
Structural conditions&lt;br /&gt;
&lt;br /&gt;
These domains will be used in this guide as place-holders:&lt;br /&gt;
&lt;br /&gt;
    mysystems.tld: Primary domain for mail accounts and mail system&lt;br /&gt;
    mail.mysystems.tld: FQDN (Fully qualified domain name) for mail host&lt;br /&gt;
    imap.mysystems.tld: Alias for mail.mysystems.tld, for imap access&lt;br /&gt;
    smtp.mysystems.tld: Alias for mail.mysystems.tld, for smtp access&lt;br /&gt;
    domain2.tld: (optional) Second domain, for which e-mails shall be sent and received&lt;br /&gt;
    domain3.tld: (optional) Third domain, for which e-mails shall be sent and received&lt;br /&gt;
&lt;br /&gt;
All these domains must be replaced by your own throughout this how-to!&lt;br /&gt;
Basic requirements&lt;br /&gt;
&lt;br /&gt;
    A virtual or dedicated server with Debian 9 “Stretch” installed. (“Basic system utilities” and SSH installed during Debian setup)&lt;br /&gt;
    At least one domain (mysystems.tld) and full control over the DNS zone and its records&lt;br /&gt;
&lt;br /&gt;
For a high quality and yet cheap, European hosting provider I recommend Hetzner.de. A small machine with two cores and 1-2 Gigs of RAM is sufficient in most cases.&lt;br /&gt;
Mail system components&lt;br /&gt;
Mailserver Schema&lt;br /&gt;
Mailserver Schema&lt;br /&gt;
Dovecot&lt;br /&gt;
&lt;br /&gt;
Dovecot is a widely spread MDA (Mail Delivery Agent) and an IMAP-server. It moves inbound e-mails into the users&#039; mailboxes and provides an IMAP interface for MUAs (Mail user agents, such as Mozilla Thunderbird) to retrieve e-mails. Furthermore, Dovecot is our SASL authentication server for Postfix.&lt;br /&gt;
Postfix&lt;br /&gt;
&lt;br /&gt;
Postfix as a popular MTA (Mail Transfer Agent) is often combined with Dovecot. While Dovecot handles the mailbox, Postfix does all the e-mail transfer tasks from client to server or from server to server.&lt;br /&gt;
MariaDB (MySQL-database)&lt;br /&gt;
&lt;br /&gt;
MariaDB will be the user accounts backend for Postfix and Dovecot. A dedicated database will contain information about our domains, user accounts, aliases and TLS policies. You can add modify and remove datasets during runtime and adapt the mail system to your needs without having to restart any services. As a bonus, the MySQL database is easily accessible e.g. for PHP scripts and you can develop your own management frontend if you wish to.&lt;br /&gt;
Rspamd&lt;br /&gt;
&lt;br /&gt;
Rspamd is a modern e-mail filter system, which replaces Amavis and Spamassassin. It also is capable of signing outbound e-mails with DKIM keys. The status of Rspamd can be monitored via a simple web interface.&lt;br /&gt;
Nginx (optional)&lt;br /&gt;
&lt;br /&gt;
Nginx is a popular HTTP web server and -proxy. It is used for comfortable and secure access to the Rpspamd webinterface.&lt;br /&gt;
Redis&lt;br /&gt;
&lt;br /&gt;
Redis is a high performance Key-Value-Store used by Rspamd. It will store data about recently seen mail servers and spam scores.&lt;br /&gt;
Preparation&lt;br /&gt;
Tip: Wipe your server&lt;br /&gt;
&lt;br /&gt;
Please consider starting from scratch! If you’ve tried other mail how-tos before, there might be leftovers, which interfere with this guide in some cases. You can avoid trouble by starting with a freshly set up Debian machine.&lt;br /&gt;
Login as Root&lt;br /&gt;
&lt;br /&gt;
You will need permananent root access during this tutorial, so switch over to your systems root account:&lt;br /&gt;
&lt;br /&gt;
su&lt;br /&gt;
&lt;br /&gt;
(Enter password for root)&lt;br /&gt;
Update system&lt;br /&gt;
&lt;br /&gt;
Get the latest software packages and linux kernel, to make sure everything works fine:&lt;br /&gt;
&lt;br /&gt;
apt update &amp;amp;&amp;amp; apt upgrade&lt;br /&gt;
&lt;br /&gt;
you might want to do a reboot to load the latest linux kernel.&lt;br /&gt;
Set hostname and FQDN&lt;br /&gt;
&lt;br /&gt;
Your server gets to names: A hostname and a FQDN (Fully qualified domain name).&lt;br /&gt;
&lt;br /&gt;
    Local hostname: For identifying your server in nyour local infrastructure. E.g. “mail”.&lt;br /&gt;
    FQDN (Fully Qualified Domain Name): For identifying your server on the internet. E.g. “mail.mysystems.tld”&lt;br /&gt;
&lt;br /&gt;
You do not need to fit your mail server’s FQDN to any domain you want to serve with it. These domains do not need to be the same or similar. Set your local hostname as follows:&lt;br /&gt;
&lt;br /&gt;
hostnamectl set-hostname --static mail&lt;br /&gt;
&lt;br /&gt;
The configuration file /etc/hosts contains FQDN and local hostname next to each other. It should be similar to this one:&lt;br /&gt;
&lt;br /&gt;
127.0.0.1	localhost&lt;br /&gt;
127.0.1.1	mail.mysystems.tld	mail&lt;br /&gt;
&lt;br /&gt;
::1         localhost ip6-localhost ip6-loopback&lt;br /&gt;
ff02::1     ip6-allnodes&lt;br /&gt;
ff02::2     ip6-allrouters&lt;br /&gt;
&lt;br /&gt;
If you enter the “hostname” and “hostname –fqdn” commands, this should be your output:&lt;br /&gt;
&lt;br /&gt;
root@mail:~# hostname&lt;br /&gt;
mail&lt;br /&gt;
root@mail:~# hostname --fqdn&lt;br /&gt;
mail.mysystems.tld&lt;br /&gt;
&lt;br /&gt;
Furthermore, the FQDN (“mail.mysystems.tld”) is copied to /etc/mailname:&lt;br /&gt;
&lt;br /&gt;
echo $(hostname -f) &amp;gt; /etc/mailname&lt;br /&gt;
&lt;br /&gt;
(The hostname in your shell prompt will adapt after a reboot)&lt;br /&gt;
Tipp: Install Unbound DNS Resolver&lt;br /&gt;
&lt;br /&gt;
Rspamd, Postfix / Postscreen and more services on your system heavily depend on DNS requests. I strongly recommend to install Unbound as a local DNS resolver and -cache! Some server providers rate-limit your access to their pre-defined DNS resolvers, which might cause trouble. Especially Rspamd does a lot of DNS requests depending on the mail system load. Furthermore, Spamhaus blocklists often can be used with own DNS resolvers only (we are going to use Spamhaus with postscreen).&lt;br /&gt;
&lt;br /&gt;
Install unbound:&lt;br /&gt;
&lt;br /&gt;
apt install unbound&lt;br /&gt;
&lt;br /&gt;
Update DNSSEC Root key and reload Unbound service:&lt;br /&gt;
&lt;br /&gt;
su -c &amp;quot;unbound-anchor -a /var/lib/unbound/root.key&amp;quot; - unbound&lt;br /&gt;
systemctl reload unbound&lt;br /&gt;
&lt;br /&gt;
The following commands will only work if the “dnsutils” package is installed to your Debian system!&lt;br /&gt;
&lt;br /&gt;
A dig @127.0.0.1 denic.de +short +dnssec should result in a similar output like this:&lt;br /&gt;
&lt;br /&gt;
dig @127.0.0.1 denic.de +short +dnssec&lt;br /&gt;
81.91.170.12&lt;br /&gt;
A 8 2 3600 20170814090000 20170731090000 26155 denic.de. Jo90qnkLkZ6gI4qNHj19BMguFuGof9hCPhdeSh/fSePSQ/WXlWMmfjW1 sNDJ/bcITRMyz8DQdDzmWPDIeSJ/qPyfoZ+BjUZxtaXcs0BAl4KX8q7h R05TGmAbgPhrYBoUKJkU/q8T+jWKHAJRUeWbCd8QOJsJbneGcUKxRAPe i6Rq51/OL/id6zUCtalhclah2TfLLaqku9PmKwjbGdZm11BXSr8b56LB WX/rdLIrKWNpE+jHGAUMmDsZL84Kx3Oo&lt;br /&gt;
&lt;br /&gt;
If the dig-command worked, you can now set Unbound as the primary DNS resolver for your mail system:&lt;br /&gt;
&lt;br /&gt;
apt install resolvconf&lt;br /&gt;
echo &amp;quot;nameserver 127.0.0.1&amp;quot; &amp;gt;&amp;gt; /etc/resolvconf/resolv.conf.d/head&lt;br /&gt;
&lt;br /&gt;
result of nslookup denic.de | grep Server should now be:&lt;br /&gt;
&lt;br /&gt;
Server:		127.0.0.1&lt;br /&gt;
&lt;br /&gt;
Now you have your own DNS resolver up and running. Let’s continue with DNS configuration …&lt;br /&gt;
DNS zone setup&lt;br /&gt;
&lt;br /&gt;
You need some DNS records set up for your mailsystem to work. Browse the management interface of your DNS provider and look for the zone files of your domains. Then add the records shown below:&lt;br /&gt;
&lt;br /&gt;
Point your system’s FQDN to its IPv4 address (and - if you have one - to your IPv6 address)&lt;br /&gt;
&lt;br /&gt;
mail.mysystems.tld. 86400 IN A    5.1.76.155&lt;br /&gt;
mail.mysystems.tld. 86400 IN AAAA 2a00:f820:417::be19:7b23&lt;br /&gt;
&lt;br /&gt;
“imap.mysystems.tld” and “smtp.mysystems.tld” are aliases for “mail.mysystems.tld”. They are not absolutely necessary, but considered “good style”. Many mail clients are looking for these domain names if you set up a new mail account.&lt;br /&gt;
&lt;br /&gt;
imap.mysystems.tld. 86400 IN CNAME mail.mysystems.tld.&lt;br /&gt;
smtp.mysystems.tld. 86400 IN CNAME mail.mysystems.tld.&lt;br /&gt;
&lt;br /&gt;
Now let’s create some MX records: Other mail servers need these to figure out, which host is responsible for mails on a certain domain. We want the host on “mail.mysystems.tld” to responsible for all e-mails, which go to @mysystemd.tld mail addresses.&lt;br /&gt;
&lt;br /&gt;
mysystems.tld. 86400 IN MX 0 mail.mysystems.tld.&lt;br /&gt;
&lt;br /&gt;
… and we also want it to handle e-mails for “domain2” and “domain3”:&lt;br /&gt;
&lt;br /&gt;
domain2.tld. 86400 IN MX 0 mail.mysystems.tld.&lt;br /&gt;
domain3.tld. 86400 IN MX 0 mail.mysystems.tld.&lt;br /&gt;
&lt;br /&gt;
(the last three entrys have to be created in their corresponding zone files)&lt;br /&gt;
Reverse DNS&lt;br /&gt;
&lt;br /&gt;
A reverse DNS record (also called “PTR record” matches a FQDN to an IP-address. Many popular e-mail providers check other mail server’s PTR records and deny receiving e-mails from them, if they cannot find a proper domain name to their IPs. You will need PTR records for all your server’s IP-addresses. They all must point to mail.mysystems.tld. In most cases reverse DNS entries can be set via your server hoster’s web interface or via the server support team.&lt;br /&gt;
SPF records&lt;br /&gt;
&lt;br /&gt;
SPF records were invented to support the fight against spam servers. Unfortunately it turned out as a miss-conception and you cannot rely on these records anymore. SPF describes which mail servers are allowed to send e-mails for a domain and which are not. In some cases (e.g. mailing lists) the SPF concept does not work. Still some providers expect you to set a SPF record - if you don’t, you’ll get some point off your “spam credibility score”. So let’s make a compromise and provide a neutral SPF record:&lt;br /&gt;
&lt;br /&gt;
mysystems.tld. 3600 IN TXT v=spf1 a:mail.mysystems.tld ?all&lt;br /&gt;
&lt;br /&gt;
Old-schooled, bad mail providers will be satisfied, and yet we don’t support bad SPF practices. The SPF record is also set for your other domains “domain2” and “domain3”, but in a slightly different way:&lt;br /&gt;
&lt;br /&gt;
domain2.tld. 3600 IN TXT v=spf1 include:mysystems.tld ?all&lt;br /&gt;
&lt;br /&gt;
DMARC records&lt;br /&gt;
&lt;br /&gt;
DMARC records set rules for foreign mail servers, which tell them how to deal with non-authenticated or incorrectly authenticated e-mails. If a spammer sends a fake e-mail and uses your domain mysystems.tld, the receiving server will consult the DNS and ask for the DMARC record. If it finds out that SPF or DKIM fail (which will be the case), the server will proceed according to the DMARC record. It is a good idea to reject such e-mails:&lt;br /&gt;
&lt;br /&gt;
_dmarc.mysystems.tld.   3600    IN TXT    v=DMARC1; p=reject;&lt;br /&gt;
&lt;br /&gt;
Set the DMARC record for your other domains accordingly:&lt;br /&gt;
&lt;br /&gt;
_dmarc.domain2.tld.   3600    IN TXT    v=DMARC1; p=reject;&lt;br /&gt;
&lt;br /&gt;
You can create your own DMARC policy records on https://elasticemail.com/dmarc/.&lt;br /&gt;
Set up TLS certificates&lt;br /&gt;
&lt;br /&gt;
A modern e-mail server can’t be operated seriously without TLS certificates. We will use Let’s Encrypt certificates for this purpose, as they are free and yet accepted by all browsers, mail clients and operating systems. If you already have valid certificates, you can use them instead.&lt;br /&gt;
Retrieve new certificates&lt;br /&gt;
&lt;br /&gt;
Use the official “certbot” command line client to get new certificates for your mail system:&lt;br /&gt;
&lt;br /&gt;
apt install certbot&lt;br /&gt;
certbot certonly --standalone --rsa-key-size 4096 -d mail.mysystems.tld -d imap.mysystems.tld -d smtp.mysystems.tld&lt;br /&gt;
&lt;br /&gt;
After having agreed to the terms of use and having provided your e-mail address you will instantly get valid certificates. They are saved at: /etc/letsencrypt/live/mail.mysystems.tld and are valid for your three mail system domain names:&lt;br /&gt;
&lt;br /&gt;
    mail.mysystems.tld&lt;br /&gt;
    imap.mysystems.tld&lt;br /&gt;
    smtp.mysystems.tld&lt;br /&gt;
&lt;br /&gt;
Your additional domains “domain2” and “domain3” do not need to be included into this certificate.&lt;br /&gt;
&lt;br /&gt;
There are some new files in /etc/letsencrypt/live/mail.mysystems.tld which you will need:&lt;br /&gt;
&lt;br /&gt;
    cert.pem: Your mailserver certificate&lt;br /&gt;
    chain.pem: CA certificate&lt;br /&gt;
    fullchain.pem: mailserver certificate + CA certificate&lt;br /&gt;
    privkey.pem: Private key for mailserver certificate&lt;br /&gt;
&lt;br /&gt;
Later in this guide only the letter two certificate files will be used.&lt;br /&gt;
Auto-Renewal&lt;br /&gt;
&lt;br /&gt;
Let’s encrypt certificates are valid for 90 days only, so they should be renewed in fixed intervals. You can achieve that via a cronjob:&lt;br /&gt;
&lt;br /&gt;
@weekly certbot renew --pre-hook &amp;quot;systemctl stop nginx&amp;quot; --post-hook &amp;quot;systemctl start nginx&amp;quot; --renew-hook &amp;quot;systemctl reload nginx; systemctl reload dovecot; systemctl reload postfix&amp;quot; --quiet&lt;br /&gt;
&lt;br /&gt;
This entry is added to the crontab file via&lt;br /&gt;
&lt;br /&gt;
crontab -e&lt;br /&gt;
&lt;br /&gt;
(select your favorite editor, paste the line above and save your changes)&lt;br /&gt;
MySQL database setup&lt;br /&gt;
&lt;br /&gt;
Install MariaDB as a DBMS (database management system)&lt;br /&gt;
&lt;br /&gt;
apt install mariadb-server&lt;br /&gt;
&lt;br /&gt;
MariaDB should be running right after its installation. You can check the service status via systemctl status mysql (not “mariadb!&amp;quot;). In case it is not yet running, start it: systemctl start mysql.&lt;br /&gt;
&lt;br /&gt;
mysql&lt;br /&gt;
&lt;br /&gt;
will get you into the MySQL shell. A few SQL commands have to be executed there to set up the database structure. Tip: Copy and paste the following SQL commands, to make sure they are formatted correctly:&lt;br /&gt;
&lt;br /&gt;
Create a new database named “vmail”:&lt;br /&gt;
&lt;br /&gt;
create database vmail&lt;br /&gt;
    CHARACTER SET &#039;utf8&#039;;&lt;br /&gt;
&lt;br /&gt;
Create database user “vmail”, with password “vmaildbpass”. This user will be used by Postfix and Dovecot. It is granted “select” permissions on this DB.&lt;br /&gt;
&lt;br /&gt;
grant select on vmail.* to &#039;vmail&#039;@&#039;localhost&#039; identified by &#039;vmaildbpass&#039;;&lt;br /&gt;
&lt;br /&gt;
Now move your SQL shell to the new database:&lt;br /&gt;
&lt;br /&gt;
use vmail;&lt;br /&gt;
&lt;br /&gt;
The following SQl commands do not need to be modified. Just copy them as they are and paste them into your SQL command line.&lt;br /&gt;
Domain table&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `domains` (&lt;br /&gt;
    `id` int unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
    `domain` varchar(255) NOT NULL,&lt;br /&gt;
    PRIMARY KEY (`id`),&lt;br /&gt;
    UNIQUE KEY (`domain`)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
The domain table contains all domains, which shall be served by the mail server.&lt;br /&gt;
Account table&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `accounts` (&lt;br /&gt;
    `id` int unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
    `username` varchar(64) NOT NULL,&lt;br /&gt;
    `domain` varchar(255) NOT NULL,&lt;br /&gt;
    `password` varchar(255) NOT NULL,&lt;br /&gt;
    `quota` int unsigned DEFAULT &#039;0&#039;,&lt;br /&gt;
    `enabled` boolean DEFAULT &#039;0&#039;,&lt;br /&gt;
    `sendonly` boolean DEFAULT &#039;0&#039;,&lt;br /&gt;
    PRIMARY KEY (id),&lt;br /&gt;
    UNIQUE KEY (`username`, `domain`),&lt;br /&gt;
    FOREIGN KEY (`domain`) REFERENCES `domains` (`domain`)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
The account table contains all data regarding user mailbox accounts, such as username, domain, password, and quota. Quota is in Megabyte (MB). If the “enabled” field if set to “true” a mailbox account is active and can be used. If “sendonly” is set to “true” this account is not able to receive mails.&lt;br /&gt;
Alias table&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `aliases` (&lt;br /&gt;
    `id` int unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
    `source_username` varchar(64) NOT NULL,&lt;br /&gt;
    `source_domain` varchar(255) NOT NULL,&lt;br /&gt;
    `destination_username` varchar(64) NOT NULL,&lt;br /&gt;
    `destination_domain` varchar(255) NOT NULL,&lt;br /&gt;
    `enabled` boolean DEFAULT &#039;0&#039;,&lt;br /&gt;
    PRIMARY KEY (`id`),&lt;br /&gt;
    UNIQUE KEY (`source_username`, `source_domain`, `destination_username`, `destination_domain`),&lt;br /&gt;
    FOREIGN KEY (`source_domain`) REFERENCES `domains` (`domain`)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
The alias table contains all alias definitions / redirects.&lt;br /&gt;
TLS Policy table&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `tlspolicies` (&lt;br /&gt;
    `id` int unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
    `domain` varchar(255) NOT NULL,&lt;br /&gt;
    `policy` enum(&#039;none&#039;, &#039;may&#039;, &#039;encrypt&#039;, &#039;dane&#039;, &#039;dane-only&#039;, &#039;fingerprint&#039;, &#039;verify&#039;, &#039;secure&#039;) NOT NULL,&lt;br /&gt;
    `params` varchar(255),&lt;br /&gt;
    PRIMARY KEY (`id`),&lt;br /&gt;
    UNIQUE KEY (`domain`)&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
The TLS policy table defines policies regarding TLS-encryption to foreign mail servers (more about that later).&lt;br /&gt;
&lt;br /&gt;
Now leave the SQL shell again, to get back to your Debian Bash Shell:&lt;br /&gt;
&lt;br /&gt;
quit;&lt;br /&gt;
&lt;br /&gt;
vmail-user and vmail-directory&lt;br /&gt;
&lt;br /&gt;
All e-mails and sieve scripts are saved into a special directory /var/vmail. Only the associated “vmail”-user has access to it. Dovecot will use this user account to do its operations on the file system.&lt;br /&gt;
&lt;br /&gt;
Create vmail-directory:&lt;br /&gt;
&lt;br /&gt;
mkdir /var/vmail&lt;br /&gt;
&lt;br /&gt;
Create vmail-user&lt;br /&gt;
&lt;br /&gt;
adduser --disabled-login --disabled-password --home /var/vmail vmail&lt;br /&gt;
&lt;br /&gt;
Create some vmail subdirectories:&lt;br /&gt;
&lt;br /&gt;
mkdir /var/vmail/mailboxes&lt;br /&gt;
mkdir -p /var/vmail/sieve/global&lt;br /&gt;
&lt;br /&gt;
vmail-user gets all permissions on /var/vmail:&lt;br /&gt;
&lt;br /&gt;
chown -R vmail /var/vmail&lt;br /&gt;
chgrp -R vmail /var/vmail&lt;br /&gt;
chmod -R 770 /var/vmail&lt;br /&gt;
&lt;br /&gt;
Install and configure Dovecot&lt;br /&gt;
&lt;br /&gt;
Install the following Dovecot components:&lt;br /&gt;
&lt;br /&gt;
apt install dovecot-core dovecot-imapd dovecot-lmtpd dovecot-mysql dovecot-sieve dovecot-managesieved&lt;br /&gt;
&lt;br /&gt;
    dovecot-core: Dovecot core&lt;br /&gt;
    dovecot-imapd: IMAP for Dovecot&lt;br /&gt;
    dovecot-lmtp: LMTP (Local Mail Transfer Protocol) for Dovecot; LMTP is used as a transmission protocol between Postfix and Dovecot.&lt;br /&gt;
    dovecot-mysql: MySQL support for Dovecot&lt;br /&gt;
    dovecot-sieve: Filter module&lt;br /&gt;
    dovecot-managesieved: Filter management server&lt;br /&gt;
&lt;br /&gt;
Dovecot is started automatically after installation. Stop is as long as we don’t have a proper configuration:&lt;br /&gt;
&lt;br /&gt;
systemctl stop dovecot&lt;br /&gt;
&lt;br /&gt;
All the Dovecot configuration files sit in ``/etc/dovecot/`. As we are going to create a Dovecot configuration from scratch, you can delete all the existing files:&lt;br /&gt;
&lt;br /&gt;
rm -r /etc/dovecot/*&lt;br /&gt;
cd /etc/dovecot&lt;br /&gt;
&lt;br /&gt;
We’ll just need two configuration files in our case: dovecot.conf and dovecot-sql.conf. Create them both in /etc/dovecot/ a follows:&lt;br /&gt;
Main configuration file dovecot.conf&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### aktivated protocols&lt;br /&gt;
#############################&lt;br /&gt;
&lt;br /&gt;
protocols = imap lmtp sieve&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### TLS configuration&lt;br /&gt;
#######################&lt;br /&gt;
&lt;br /&gt;
ssl = required&lt;br /&gt;
ssl_cert = &amp;lt;/etc/letsencrypt/live/mail.mysystems.tld/fullchain.pem&lt;br /&gt;
ssl_key = &amp;lt;/etc/letsencrypt/live/mail.mysystems.tld/privkey.pem&lt;br /&gt;
ssl_cipher_list = EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA&lt;br /&gt;
ssl_prefer_server_ciphers = yes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### Dovecot services&lt;br /&gt;
################################&lt;br /&gt;
&lt;br /&gt;
service imap-login {&lt;br /&gt;
    inet_listener imap {&lt;br /&gt;
        port = 143&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
service managesieve-login {&lt;br /&gt;
    inet_listener sieve {&lt;br /&gt;
        port = 4190&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
service lmtp {&lt;br /&gt;
    unix_listener /var/spool/postfix/private/dovecot-lmtp {&lt;br /&gt;
        mode = 0660&lt;br /&gt;
        group = postfix&lt;br /&gt;
        user = postfix&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    user = vmail&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
service auth {&lt;br /&gt;
    ### Auth socket für Postfix&lt;br /&gt;
    unix_listener /var/spool/postfix/private/auth {&lt;br /&gt;
        mode = 0660&lt;br /&gt;
        user = postfix&lt;br /&gt;
        group = postfix&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    ### Auth socket für LMTP-Dienst&lt;br /&gt;
    unix_listener auth-userdb {&lt;br /&gt;
        mode = 0660&lt;br /&gt;
        user = vmail&lt;br /&gt;
        group = vmail&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
###  Protocol settings&lt;br /&gt;
#############################&lt;br /&gt;
&lt;br /&gt;
protocol imap {&lt;br /&gt;
    mail_plugins = $mail_plugins quota imap_quota imap_sieve&lt;br /&gt;
    mail_max_userip_connections = 20&lt;br /&gt;
    imap_idle_notify_interval = 29 mins&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
protocol lmtp {&lt;br /&gt;
    postmaster_address = postmaster@mysystems.tld&lt;br /&gt;
    mail_plugins = $mail_plugins sieve&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### Client authentication&lt;br /&gt;
#############################&lt;br /&gt;
&lt;br /&gt;
disable_plaintext_auth = yes&lt;br /&gt;
auth_mechanisms = plain login&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
passdb {&lt;br /&gt;
    driver = sql&lt;br /&gt;
    args = /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
userdb {&lt;br /&gt;
    driver = sql&lt;br /&gt;
    args = /etc/dovecot/dovecot-sql.conf&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### Mail location&lt;br /&gt;
#######################&lt;br /&gt;
&lt;br /&gt;
mail_uid = vmail&lt;br /&gt;
mail_gid = vmail&lt;br /&gt;
mail_privileged_group = vmail&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mail_home = /var/vmail/mailboxes/%d/%n&lt;br /&gt;
mail_location = maildir:~/mail:LAYOUT=fs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### Mailbox configuration&lt;br /&gt;
########################################&lt;br /&gt;
&lt;br /&gt;
namespace inbox {&lt;br /&gt;
    inbox = yes&lt;br /&gt;
&lt;br /&gt;
    mailbox Spam {&lt;br /&gt;
        auto = subscribe&lt;br /&gt;
        special_use = \Junk&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    mailbox Trash {&lt;br /&gt;
        auto = subscribe&lt;br /&gt;
        special_use = \Trash&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    mailbox Drafts {&lt;br /&gt;
        auto = subscribe&lt;br /&gt;
        special_use = \Drafts&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    mailbox Sent {&lt;br /&gt;
        auto = subscribe&lt;br /&gt;
        special_use = \Sent&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
###&lt;br /&gt;
### Mail plugins&lt;br /&gt;
############################&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
plugin {&lt;br /&gt;
    sieve_plugins = sieve_imapsieve sieve_extprograms&lt;br /&gt;
    sieve_before = /var/vmail/sieve/global/spam-global.sieve&lt;br /&gt;
    sieve = file:/var/vmail/sieve/%d/%n/scripts;active=/var/vmail/sieve/%d/%n/active-script.sieve&lt;br /&gt;
&lt;br /&gt;
    ###&lt;br /&gt;
    ### Spam learning&lt;br /&gt;
    ###&lt;br /&gt;
    # From elsewhere to Spam folder&lt;br /&gt;
    imapsieve_mailbox1_name = Spam&lt;br /&gt;
    imapsieve_mailbox1_causes = COPY&lt;br /&gt;
    imapsieve_mailbox1_before = file:/var/vmail/sieve/global/learn-spam.sieve&lt;br /&gt;
&lt;br /&gt;
    # From Spam folder to elsewhere&lt;br /&gt;
    imapsieve_mailbox2_name = *&lt;br /&gt;
    imapsieve_mailbox2_from = Spam&lt;br /&gt;
    imapsieve_mailbox2_causes = COPY&lt;br /&gt;
    imapsieve_mailbox2_before = file:/var/vmail/sieve/global/learn-ham.sieve&lt;br /&gt;
&lt;br /&gt;
    sieve_pipe_bin_dir = /usr/bin&lt;br /&gt;
    sieve_global_extensions = +vnd.dovecot.pipe&lt;br /&gt;
&lt;br /&gt;
    quota = maildir:User quota&lt;br /&gt;
    quota_exceeded_message = Benutzer %u hat das Speichervolumen überschritten. / User %u has exhausted allowed storage space.&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Settings to adjust:&lt;br /&gt;
&lt;br /&gt;
    ssl_cert: Path to certificate file&lt;br /&gt;
    ssl_key: Path to certificate key&lt;br /&gt;
    postmaster_address: Fit to your primary domain&lt;br /&gt;
&lt;br /&gt;
SQL configuration file dovecot-sql.conf&lt;br /&gt;
&lt;br /&gt;
driver=mysql&lt;br /&gt;
connect = &amp;quot;host=127.0.0.1 dbname=vmail user=vmail password=vmaildbpass&amp;quot;&lt;br /&gt;
default_pass_scheme = SHA512-CRYPT&lt;br /&gt;
&lt;br /&gt;
password_query = SELECT username AS user, domain, password FROM accounts WHERE username = &#039;%n&#039; AND domain = &#039;%d&#039; and enabled = true;&lt;br /&gt;
user_query = SELECT concat(&#039;*:storage=&#039;, quota, &#039;M&#039;) AS quota_rule FROM accounts WHERE username = &#039;%n&#039; AND domain = &#039;%d&#039; AND sendonly = false;&lt;br /&gt;
iterate_query = SELECT username, domain FROM accounts where sendonly = false;&lt;br /&gt;
&lt;br /&gt;
Settings to adjust:&lt;br /&gt;
&lt;br /&gt;
    Database password “vmaildbpass”&lt;br /&gt;
&lt;br /&gt;
Set proper permissions for dovecot-sql.conf:&lt;br /&gt;
&lt;br /&gt;
chmod 440 dovecot-sql.conf&lt;br /&gt;
&lt;br /&gt;
Global sieve filter to move marked spam mails&lt;br /&gt;
&lt;br /&gt;
Create a new Sieve filter script spam-global.sieve in /var/vmail/sieve/global/&lt;br /&gt;
&lt;br /&gt;
require &amp;quot;fileinto&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
if header :contains &amp;quot;X-Spam-Flag&amp;quot; &amp;quot;YES&amp;quot; {&lt;br /&gt;
    fileinto &amp;quot;Spam&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if header :is &amp;quot;X-Spam&amp;quot; &amp;quot;Yes&amp;quot; {&lt;br /&gt;
    fileinto &amp;quot;Spam&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Spam learning with Rspamd&lt;br /&gt;
&lt;br /&gt;
Rspamd shall learn from its mistakes if you move a mail out of your “Spam” folder and vice versa. Sieve recognizes the moving process and triggers a Rspam learning process. Create to following two sieve config files in /var/vmail/sieve/global/:&lt;br /&gt;
&lt;br /&gt;
learn-spam.sieve&lt;br /&gt;
&lt;br /&gt;
require [&amp;quot;vnd.dovecot.pipe&amp;quot;, &amp;quot;copy&amp;quot;, &amp;quot;imapsieve&amp;quot;];&lt;br /&gt;
pipe :copy &amp;quot;rspamc&amp;quot; [&amp;quot;learn_spam&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
learn-ham.sieve&lt;br /&gt;
&lt;br /&gt;
require [&amp;quot;vnd.dovecot.pipe&amp;quot;, &amp;quot;copy&amp;quot;, &amp;quot;imapsieve&amp;quot;, &amp;quot;environment&amp;quot;, &amp;quot;variables&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
if environment :matches &amp;quot;imap.mailbox&amp;quot; &amp;quot;*&amp;quot; {&lt;br /&gt;
    set &amp;quot;mailbox&amp;quot; &amp;quot;${1}&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if string &amp;quot;${mailbox}&amp;quot; &amp;quot;Trash&amp;quot; {&lt;br /&gt;
    stop;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
pipe :copy &amp;quot;rspamc&amp;quot; [&amp;quot;learn_ham&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
Install and configure Postfix&lt;br /&gt;
&lt;br /&gt;
Install:&lt;br /&gt;
&lt;br /&gt;
apt install postfix postfix-mysql&lt;br /&gt;
&lt;br /&gt;
During installation of the Postfix packages you will be asked what type of configuration you want to create. Select “No configuration”. Then stop Postfix:&lt;br /&gt;
&lt;br /&gt;
systemctl stop postfix&lt;br /&gt;
&lt;br /&gt;
Although you selected “No configuration” there will be configuration files in /etc/postfix. Delete some of them:&lt;br /&gt;
&lt;br /&gt;
cd /etc/postfix&lt;br /&gt;
rm -r sasl&lt;br /&gt;
rm master.cf main.cf.proto master.cf.proto&lt;br /&gt;
&lt;br /&gt;
Then create the following new config files in /etc/postfix:&lt;br /&gt;
main.cf&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Network settings&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128&lt;br /&gt;
inet_interfaces = 127.0.0.1, ::1, 5.1.76.152, 2a00:f820:417::7647:b2c2&lt;br /&gt;
myhostname = mail.mysystems.tld&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Mail queue settings&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
maximal_queue_lifetime = 1h&lt;br /&gt;
bounce_queue_lifetime = 1h&lt;br /&gt;
maximal_backoff_time = 15m&lt;br /&gt;
minimal_backoff_time = 5m&lt;br /&gt;
queue_run_delay = 5m&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## TLS settings&lt;br /&gt;
###&lt;br /&gt;
&lt;br /&gt;
tls_preempt_cipherlist = yes&lt;br /&gt;
tls_ssl_options = NO_COMPRESSION&lt;br /&gt;
tls_high_cipherlist = EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### Outbound SMTP connections (Postfix as sender)&lt;br /&gt;
&lt;br /&gt;
smtp_tls_security_level = dane&lt;br /&gt;
smtp_dns_support_level = dnssec&lt;br /&gt;
smtp_tls_policy_maps = mysql:/etc/postfix/sql/tls-policy.cf&lt;br /&gt;
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache&lt;br /&gt;
smtp_tls_protocols = !SSLv2, !SSLv3&lt;br /&gt;
smtp_tls_ciphers = high&lt;br /&gt;
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### Inbound SMTP connections&lt;br /&gt;
&lt;br /&gt;
smtpd_tls_security_level = may&lt;br /&gt;
smtpd_tls_protocols = !SSLv2, !SSLv3&lt;br /&gt;
smtpd_tls_ciphers = high&lt;br /&gt;
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache&lt;br /&gt;
&lt;br /&gt;
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.mysystems.tld/fullchain.pem&lt;br /&gt;
smtpd_tls_key_file=/etc/letsencrypt/live/mail.mysystems.tld/privkey.pem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Local mail delivery to Dovecot via LMTP&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
virtual_transport = lmtp:unix:private/dovecot-lmtp&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Spam filter and DKIM signatures via Rspamd&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
smtpd_milters = inet:localhost:11332&lt;br /&gt;
non_smtpd_milters = inet:localhost:11332&lt;br /&gt;
milter_protocol = 6&lt;br /&gt;
milter_mail_macros =  i {mail_addr} {client_addr} {client_name} {auth_authen}&lt;br /&gt;
milter_default_action = accept&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Server Restrictions for clients, cecipients and relaying&lt;br /&gt;
## (concerning S2S-connections. Mailclient-connections are configured in submission-section in master.cf)&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
### Conditions in which Postfix works as a relay. (for mail user clients)&lt;br /&gt;
smtpd_relay_restrictions =      reject_non_fqdn_recipient&lt;br /&gt;
                                reject_unknown_recipient_domain&lt;br /&gt;
                                permit_mynetworks&lt;br /&gt;
                                reject_unauth_destination&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### Conditions in which Postfix accepts e-mails as recipient (additional to relay conditions)&lt;br /&gt;
### check_recipient_access checks if an account is &amp;quot;sendonly&amp;quot;&lt;br /&gt;
smtpd_recipient_restrictions = check_recipient_access mysql:/etc/postfix/sql/recipient-access.cf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### Restrictions for all sending foreign servers (&amp;quot;SMTP clients&amp;quot;)&lt;br /&gt;
smtpd_client_restrictions =     permit_mynetworks&lt;br /&gt;
                                check_client_access hash:/etc/postfix/without_ptr&lt;br /&gt;
                                reject_unknown_client_hostname&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### Foreign mail servers must present a valid &amp;quot;HELO&amp;quot;&lt;br /&gt;
smtpd_helo_required = yes&lt;br /&gt;
smtpd_helo_restrictions =   permit_mynetworks&lt;br /&gt;
                            reject_invalid_helo_hostname&lt;br /&gt;
                            reject_non_fqdn_helo_hostname&lt;br /&gt;
                            reject_unknown_helo_hostname&lt;br /&gt;
&lt;br /&gt;
# Block clients, which start sending too early&lt;br /&gt;
smtpd_data_restrictions = reject_unauth_pipelining&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Restrictions for MUAs (Mail user agents)&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
mua_relay_restrictions = reject_non_fqdn_recipient,reject_unknown_recipient_domain,permit_mynetworks,permit_sasl_authenticated,reject&lt;br /&gt;
mua_sender_restrictions = permit_mynetworks,reject_non_fqdn_sender,reject_sender_login_mismatch,permit_sasl_authenticated,reject&lt;br /&gt;
mua_client_restrictions = permit_mynetworks,permit_sasl_authenticated,reject&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Postscreen Filter&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
### Postscreen Whitelist / Blocklist&lt;br /&gt;
postscreen_access_list =        permit_mynetworks&lt;br /&gt;
                                cidr:/etc/postfix/postscreen_access&lt;br /&gt;
postscreen_blacklist_action = drop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Drop connections if other server is sending too quickly&lt;br /&gt;
postscreen_greet_action = drop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
### DNS blocklists&lt;br /&gt;
postscreen_dnsbl_threshold = 2&lt;br /&gt;
postscreen_dnsbl_sites =    ix.dnsbl.manitu.net*2&lt;br /&gt;
                            zen.spamhaus.org*2&lt;br /&gt;
postscreen_dnsbl_action = drop&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## MySQL queries&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
virtual_alias_maps = mysql:/etc/postfix/sql/aliases.cf&lt;br /&gt;
virtual_mailbox_maps = mysql:/etc/postfix/sql/accounts.cf&lt;br /&gt;
virtual_mailbox_domains = mysql:/etc/postfix/sql/domains.cf&lt;br /&gt;
local_recipient_maps = $virtual_mailbox_maps&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
##&lt;br /&gt;
## Miscellaneous&lt;br /&gt;
##&lt;br /&gt;
&lt;br /&gt;
### Maximum mailbox size (0=unlimited - is already limited by Dovecot quota)&lt;br /&gt;
mailbox_size_limit = 0&lt;br /&gt;
&lt;br /&gt;
### Maximum size of inbound e-mails (50 MB)&lt;br /&gt;
message_size_limit = 52428800&lt;br /&gt;
&lt;br /&gt;
### Do not notify system users on new e-mail&lt;br /&gt;
biff = no&lt;br /&gt;
&lt;br /&gt;
### Users always have to provide full e-mail addresses&lt;br /&gt;
append_dot_mydomain = no&lt;br /&gt;
&lt;br /&gt;
### Delimiter for &amp;quot;Address Tagging&amp;quot;&lt;br /&gt;
recipient_delimiter = +&lt;br /&gt;
&lt;br /&gt;
Settings to adjust:&lt;br /&gt;
&lt;br /&gt;
    inet_interfaces: IP addresses of your server. 5.1.76.152, 2a00:f820:417::7647:b2c2 must be replaced by your own IPv4- and IPv6-address.&lt;br /&gt;
    myhostname: Replace by your own hostname&lt;br /&gt;
    smtpd_tls_cert_file: Path to certificate file&lt;br /&gt;
    smtpd_tls_key_file: Path to certificate key&lt;br /&gt;
&lt;br /&gt;
Configuration file master.cf&lt;br /&gt;
&lt;br /&gt;
# ==========================================================================&lt;br /&gt;
# service type  private unpriv  chroot  wakeup  maxproc command + args&lt;br /&gt;
#               (yes)   (yes)   (no)    (never) (100)&lt;br /&gt;
# ==========================================================================&lt;br /&gt;
smtp      inet  n       -       y       -       1       postscreen&lt;br /&gt;
    -o smtpd_sasl_auth_enable=no&lt;br /&gt;
smtpd     pass  -       -       y       -       -       smtpd&lt;br /&gt;
dnsblog   unix  -       -       y       -       0       dnsblog&lt;br /&gt;
tlsproxy  unix  -       -       y       -       0       tlsproxy&lt;br /&gt;
submission inet n       -       y       -       -       smtpd&lt;br /&gt;
    -o syslog_name=postfix/submission&lt;br /&gt;
    -o smtpd_tls_security_level=encrypt&lt;br /&gt;
    -o smtpd_sasl_auth_enable=yes&lt;br /&gt;
    -o smtpd_sasl_type=dovecot&lt;br /&gt;
    -o smtpd_sasl_path=private/auth&lt;br /&gt;
    -o smtpd_sasl_security_options=noanonymous&lt;br /&gt;
    -o smtpd_client_restrictions=$mua_client_restrictions&lt;br /&gt;
    -o smtpd_sender_restrictions=$mua_sender_restrictions&lt;br /&gt;
    -o smtpd_relay_restrictions=$mua_relay_restrictions&lt;br /&gt;
    -o milter_macro_daemon_name=ORIGINATING&lt;br /&gt;
    -o smtpd_sender_login_maps=mysql:/etc/postfix/sql/sender-login-maps.cf&lt;br /&gt;
    -o smtpd_helo_required=no&lt;br /&gt;
    -o smtpd_helo_restrictions=&lt;br /&gt;
    -o cleanup_service_name=submission-header-cleanup&lt;br /&gt;
pickup    unix  n       -       y       60      1       pickup&lt;br /&gt;
cleanup   unix  n       -       y       -       0       cleanup&lt;br /&gt;
qmgr      unix  n       -       n       300     1       qmgr&lt;br /&gt;
tlsmgr    unix  -       -       y       1000?   1       tlsmgr&lt;br /&gt;
rewrite   unix  -       -       y       -       -       trivial-rewrite&lt;br /&gt;
bounce    unix  -       -       y       -       0       bounce&lt;br /&gt;
defer     unix  -       -       y       -       0       bounce&lt;br /&gt;
trace     unix  -       -       y       -       0       bounce&lt;br /&gt;
verify    unix  -       -       y       -       1       verify&lt;br /&gt;
flush     unix  n       -       y       1000?   0       flush&lt;br /&gt;
proxymap  unix  -       -       n       -       -       proxymap&lt;br /&gt;
proxywrite unix -       -       n       -       1       proxymap&lt;br /&gt;
smtp      unix  -       -       y       -       -       smtp&lt;br /&gt;
relay     unix  -       -       y       -       -       smtp&lt;br /&gt;
showq     unix  n       -       y       -       -       showq&lt;br /&gt;
error     unix  -       -       y       -       -       error&lt;br /&gt;
retry     unix  -       -       y       -       -       error&lt;br /&gt;
discard   unix  -       -       y       -       -       discard&lt;br /&gt;
local     unix  -       n       n       -       -       local&lt;br /&gt;
virtual   unix  -       n       n       -       -       virtual&lt;br /&gt;
lmtp      unix  -       -       y       -       -       lmtp&lt;br /&gt;
anvil     unix  -       -       y       -       1       anvil&lt;br /&gt;
scache    unix  -       -       y       -       1       scache&lt;br /&gt;
submission-header-cleanup unix n - n    -       0       cleanup&lt;br /&gt;
    -o header_checks=regexp:/etc/postfix/submission_header_cleanup&lt;br /&gt;
&lt;br /&gt;
Header cleanup rules&lt;br /&gt;
&lt;br /&gt;
Create a new file /etc/postfix/submission_header_cleanup with this content:&lt;br /&gt;
&lt;br /&gt;
### Removes headers of MUAs for privacy reasons&lt;br /&gt;
&lt;br /&gt;
/^Received:/            IGNORE&lt;br /&gt;
/^X-Originating-IP:/    IGNORE&lt;br /&gt;
/^X-Mailer:/            IGNORE&lt;br /&gt;
/^User-Agent:/          IGNORE&lt;br /&gt;
&lt;br /&gt;
SQL configuration&lt;br /&gt;
&lt;br /&gt;
SQL queries for Postfix sit in the sql/ subdirectory:&lt;br /&gt;
&lt;br /&gt;
mkdir /etc/postfix/sql &amp;amp;&amp;amp; cd $_&lt;br /&gt;
&lt;br /&gt;
Create these files with their corresponding content:&lt;br /&gt;
&lt;br /&gt;
accounts.cf&lt;br /&gt;
&lt;br /&gt;
user = vmail&lt;br /&gt;
password = vmaildbpass&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = vmail&lt;br /&gt;
query = select 1 as found from accounts where username = &#039;%u&#039; and domain = &#039;%d&#039; and enabled = true LIMIT 1;&lt;br /&gt;
&lt;br /&gt;
aliases.cf&lt;br /&gt;
&lt;br /&gt;
user = vmail&lt;br /&gt;
password = vmaildbpass&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = vmail&lt;br /&gt;
query = select concat(destination_username, &#039;@&#039;, destination_domain) as destinations from aliases where source_username = &#039;%u&#039; and source_domain = &#039;%d&#039; and enabled = true;&lt;br /&gt;
&lt;br /&gt;
domains.cf&lt;br /&gt;
&lt;br /&gt;
user = vmail&lt;br /&gt;
password = vmaildbpass&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = vmail&lt;br /&gt;
query = SELECT domain FROM domains WHERE domain=&#039;%s&#039;&lt;br /&gt;
&lt;br /&gt;
recipient-access.cf&lt;br /&gt;
&lt;br /&gt;
user = vmail&lt;br /&gt;
password = vmaildbpass&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = vmail&lt;br /&gt;
query = select if(sendonly = true, &#039;REJECT&#039;, &#039;OK&#039;) AS access from accounts where username = &#039;%u&#039; and domain = &#039;%d&#039; and enabled = true LIMIT 1;&lt;br /&gt;
&lt;br /&gt;
sender-login-maps.cf&lt;br /&gt;
&lt;br /&gt;
user = vmail&lt;br /&gt;
password = vmaildbpass&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = vmail&lt;br /&gt;
query = select concat(username, &#039;@&#039;, domain) as &#039;owns&#039; from accounts where username = &#039;%u&#039; AND domain = &#039;%d&#039; and enabled = true union select concat(destination_username, &#039;@&#039;, destination_domain) AS &#039;owns&#039; from aliases where source_username = &#039;%u&#039; and source_domain = &#039;%d&#039; and enabled = true;&lt;br /&gt;
&lt;br /&gt;
tls-policy.cf&lt;br /&gt;
&lt;br /&gt;
user = vmail&lt;br /&gt;
password = vmaildbpass&lt;br /&gt;
hosts = 127.0.0.1&lt;br /&gt;
dbname = vmail&lt;br /&gt;
query = SELECT policy, params FROM tlspolicies WHERE domain = &#039;%s&#039;&lt;br /&gt;
&lt;br /&gt;
Don’t forget to modify vmaildbpass in all of the above files, in case you are using another password!&lt;br /&gt;
&lt;br /&gt;
Set proper permissions for /etc/postfix/sql:&lt;br /&gt;
&lt;br /&gt;
chmod -R 640 /etc/postfix/sql&lt;br /&gt;
&lt;br /&gt;
More Postfix configuration files&lt;br /&gt;
&lt;br /&gt;
Create two new files in /etc/postfix. You can leave them empty.&lt;br /&gt;
&lt;br /&gt;
touch /etc/postfix/without_ptr&lt;br /&gt;
touch /etc/postfix/postscreen_access&lt;br /&gt;
&lt;br /&gt;
In without_ptr you can define entries like this:&lt;br /&gt;
&lt;br /&gt;
1.2.3.3 OK&lt;br /&gt;
&lt;br /&gt;
This will result in a policy, which allows server 1.2.3.3 to send e-mails to this host even if it does not have a valid PTR-record. After every change, without_ptr has to be converted into a database file and Postfix must be reloaded:&lt;br /&gt;
&lt;br /&gt;
postmap /etc/postfix/without_ptr&lt;br /&gt;
systemctl reload postfix&lt;br /&gt;
&lt;br /&gt;
For the moment, just create an empty database file:&lt;br /&gt;
&lt;br /&gt;
postmap /etc/postfix/without_ptr&lt;br /&gt;
&lt;br /&gt;
In postscreen_access you can define exceptions for the postscreen filter. If any mail server is blocked by postscreen and you want to grant access for any reason, add an entry similar to the following:&lt;br /&gt;
&lt;br /&gt;
1.2.3.3 permit&lt;br /&gt;
&lt;br /&gt;
You can do the opposite, too: If you always want to block a certain server, add “reject” instead of “permit”.&lt;br /&gt;
&lt;br /&gt;
Execute&lt;br /&gt;
&lt;br /&gt;
newaliases&lt;br /&gt;
&lt;br /&gt;
to create the alias database file /etc/aliases.db. This file is expected by Postfix by default.&lt;br /&gt;
Rspamd&lt;br /&gt;
&lt;br /&gt;
The official Debian repositories contain an outdated version of Rspamd, so use the Rspamd-Repository for installation instead:&lt;br /&gt;
&lt;br /&gt;
apt install -y lsb-release wget&lt;br /&gt;
wget -O- https://rspamd.com/apt-stable/gpg.key | apt-key add -&lt;br /&gt;
echo &amp;quot;deb http://rspamd.com/apt-stable/ $(lsb_release -c -s) main&amp;quot; &amp;gt; /etc/apt/sources.list.d/rspamd.list&lt;br /&gt;
echo &amp;quot;deb-src http://rspamd.com/apt-stable/ $(lsb_release -c -s) main&amp;quot; &amp;gt;&amp;gt; /etc/apt/sources.list.d/rspamd.list&lt;br /&gt;
&lt;br /&gt;
Update package sources and install Rspamd:&lt;br /&gt;
&lt;br /&gt;
apt update&lt;br /&gt;
apt install rspamd&lt;br /&gt;
&lt;br /&gt;
Stop Rspamd service&lt;br /&gt;
&lt;br /&gt;
systemctl stop rspamd&lt;br /&gt;
&lt;br /&gt;
Basic configuration&lt;br /&gt;
&lt;br /&gt;
Following files are now created in /etc/rspamd/local.d/:&lt;br /&gt;
&lt;br /&gt;
/etc/rspamd/local.d/options.inc: Network settings and definition of the DNS resolver to use.&lt;br /&gt;
&lt;br /&gt;
local_addrs = &amp;quot;127.0.0.0/8, ::1&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
dns {&lt;br /&gt;
    nameserver = [&amp;quot;127.0.0.1:53:10&amp;quot;];&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/etc/rspamd/local.d/worker-normal.inc: Settings for the normal Rspamd worker&lt;br /&gt;
&lt;br /&gt;
bind_socket = &amp;quot;localhost:11333&amp;quot;;&lt;br /&gt;
### Anzahl der zu nutzenden Worker. Standard: Anzahl der virtuellen Prozessorkerne.&lt;br /&gt;
# count = 1&lt;br /&gt;
&lt;br /&gt;
/etc/rspamd/local.d/worker-controller.inc: Worker controller settings: Password for web interface access, e.g.:&lt;br /&gt;
&lt;br /&gt;
password = &amp;quot;$2$qecacwgrz13owkag4gqcy5y7yeqh7yh4$y6i6gn5q3538tzsn19ojchuudoauw3rzdj1z74h5us4gd3jj5e8y&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
The password hash (&amp;quot;$2$ …&amp;quot;) must be generated by&lt;br /&gt;
&lt;br /&gt;
rspamadm pw&lt;br /&gt;
&lt;br /&gt;
before. Enter a password you would like to set, copy the hash and paste it into the configuration file above (instead of my example hash).&lt;br /&gt;
&lt;br /&gt;
/etc/rspamd/local.d/worker-proxy.inc: Worker proxy (Milter-Module for Postfix)&lt;br /&gt;
&lt;br /&gt;
bind_socket = &amp;quot;localhost:11332&amp;quot;;&lt;br /&gt;
milter = yes;&lt;br /&gt;
timeout = 120s;&lt;br /&gt;
upstream &amp;quot;local&amp;quot; {&lt;br /&gt;
    default = yes;&lt;br /&gt;
    self_scan = yes;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/etc/rspamd/local.d/logging.inc: Error logging&lt;br /&gt;
&lt;br /&gt;
type = &amp;quot;file&amp;quot;;&lt;br /&gt;
filename = &amp;quot;/var/log/rspamd/rspamd.log&amp;quot;;&lt;br /&gt;
level = &amp;quot;error&amp;quot;;&lt;br /&gt;
debug_modules = [];&lt;br /&gt;
&lt;br /&gt;
Milter Headers /etc/rspamd/local.d/milter_headers.conf&lt;br /&gt;
&lt;br /&gt;
use = [&amp;quot;x-spamd-bar&amp;quot;, &amp;quot;x-spam-level&amp;quot;, &amp;quot;authentication-results&amp;quot;];&lt;br /&gt;
authenticated_headers = [&amp;quot;authentication-results&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
Use Redis for Bayesian filter: /etc/rspamd/local.d/classifier-bayes.conf&lt;br /&gt;
&lt;br /&gt;
backend = &amp;quot;redis&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
DKIM signing&lt;br /&gt;
&lt;br /&gt;
Rspamd not only handles spam mail filtering, but also is capable of signing e-mails via DKIM. First, a signing key must be created:&lt;br /&gt;
&lt;br /&gt;
mkdir /var/lib/rspamd/dkim/&lt;br /&gt;
rspamadm dkim_keygen -b 2048 -s 2017 -k /var/lib/rspamd/dkim/2017.key &amp;gt; /var/lib/rspamd/dkim/2017.txt&lt;br /&gt;
chown -R _rspamd:_rspamd /var/lib/rspamd/dkim&lt;br /&gt;
chmod 440 /var/lib/rspamd/dkim/*&lt;br /&gt;
&lt;br /&gt;
2017 is the name of the DKIM key (also called “selector”). I’m using the current year as a name. For a DKIM signing key (/var/lib/rspamd/dkim/2017.key) there is also a corresponding public key, which has to be published in the DNS. An example of a record with this key is given in /var/lib/rspamd/dkim/2017.txt&lt;br /&gt;
&lt;br /&gt;
Output example DNS record with public key:&lt;br /&gt;
&lt;br /&gt;
cat /var/lib/rspamd/dkim/2017.txt&lt;br /&gt;
&lt;br /&gt;
Example output:&lt;br /&gt;
&lt;br /&gt;
2017._domainkey IN TXT ( &amp;quot;v=DKIM1; k=rsa; &amp;quot;&lt;br /&gt;
	&amp;quot;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2/al5HqXUpe+HUazCr6t9lv2VOZLR369PPB4t+dgljZQvgUsIKoYzfS/w9NagS32xZYxi1dtlDWuRfTU/ahHO2MYzE0zHE4lMfwb6VkNCG+pM6bAkCwc5cFvyRygwxAPEiHAtmtU5b0i9LY25Z/ZWgyBxEWZ0Wf+hLjYHvnvMqewPsduUqKVjDOdUqeBb1VAu3WFErOAGVUYfKqFX&amp;quot;&lt;br /&gt;
	&amp;quot;+yfz36Alb7/OMAort8A5Vo5t5k0vxTHzkYYg5KB6tLS8jngrNucGjyNL5+k0ijPs3yT7WpTGL3U3SEa8cX8WvOO1fIpWQz4yyZJJ1Mm62+FskSc7BHjdiMHE64Id/UBDDVjxwIDAQAB&amp;quot;&lt;br /&gt;
) ;&lt;br /&gt;
&lt;br /&gt;
The important part starts with v=DKIM1 and ends with AQAB (in this example). Now put this part of the output into a new DNS record. To illustrate the process, I did this step for my DNS hoster and made a screenshot:&lt;br /&gt;
core-networks.de Screenshot mit DKIM Record&lt;br /&gt;
core-networks.de Screenshot mit DKIM Record&lt;br /&gt;
&lt;br /&gt;
Make sure the _domainkey-subdomain-prefix matches your selector prefix! (“2017”) The DKIM Record must be added to every domain / zone file in use - not only your primary domain!&lt;br /&gt;
If your record is not accepted by your DNS hoster, a 2048 bit key might be too long. You can generate a shorter key by specifying -b 1024 instead of -b 2048 and running the rspamadm dkim_keygen command again.&lt;br /&gt;
&lt;br /&gt;
Create /etc/rspamd/local.d/dkim_signing.conf and set “2017” as the selector:&lt;br /&gt;
&lt;br /&gt;
path = &amp;quot;/var/lib/rspamd/dkim/$selector.key&amp;quot;;&lt;br /&gt;
selector = &amp;quot;2017&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
### Enable DKIM signing for alias sender addresses&lt;br /&gt;
allow_username_mismatch = true;&lt;br /&gt;
&lt;br /&gt;
This configuration is also copied to /etc/rspamd/local.d/arc.conf, since the ARC module makes use of the same parameters.&lt;br /&gt;
&lt;br /&gt;
cp -R /etc/rspamd/local.d/dkim_signing.conf /etc/rspamd/local.d/arc.conf&lt;br /&gt;
&lt;br /&gt;
Redis&lt;br /&gt;
&lt;br /&gt;
Rspamd uses Redis as a data cache. Installation is simple:&lt;br /&gt;
&lt;br /&gt;
apt install redis-server&lt;br /&gt;
&lt;br /&gt;
/etc/rspamd/local.d/redis.conf&lt;br /&gt;
&lt;br /&gt;
servers = &amp;quot;127.0.0.1&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Start Rspamd&lt;br /&gt;
&lt;br /&gt;
systemctl start rspamd&lt;br /&gt;
&lt;br /&gt;
Nginx Proxy for Rspamd web interface (optional)&lt;br /&gt;
&lt;br /&gt;
So get easy and secure access to the Rspamd web interface, you can install Nginx as a HTTP proxy with TLS-termination. As an alternative, access via a SSH tunnel is sufficient in some cases (see below).&lt;br /&gt;
&lt;br /&gt;
Installation:&lt;br /&gt;
&lt;br /&gt;
apt install nginx&lt;br /&gt;
nano /etc/nginx/sites-available/mail.mysystems.tld&lt;br /&gt;
&lt;br /&gt;
Config file /etc/nginx/sites-available/mail.mysystems.tld&lt;br /&gt;
&lt;br /&gt;
server {&lt;br /&gt;
    listen 80;&lt;br /&gt;
    listen [::]:80;&lt;br /&gt;
    listen 443 ssl http2;&lt;br /&gt;
    listen [::]:443 ssl http2;&lt;br /&gt;
&lt;br /&gt;
    ssl_certificate /etc/letsencrypt/live/mail.mysystems.tld/fullchain.pem;&lt;br /&gt;
    ssl_certificate_key /etc/letsencrypt/live/mail.mysystems.tld/privkey.pem;&lt;br /&gt;
&lt;br /&gt;
    server_name mail.mysystems.tld;&lt;br /&gt;
&lt;br /&gt;
    root /var/www/default;&lt;br /&gt;
&lt;br /&gt;
    if ($ssl_protocol = &amp;quot;&amp;quot;) {&lt;br /&gt;
        return 301 https://$server_name$request_uri;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    location /rspamd/ {&lt;br /&gt;
        proxy_pass http://localhost:11334/;&lt;br /&gt;
        proxy_set_header Host $host;&lt;br /&gt;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Settings to adapt:&lt;br /&gt;
&lt;br /&gt;
    ssl_certificate: Path to certificate&lt;br /&gt;
    ssl_certificate_key: Path to certificate key&lt;br /&gt;
    server_name&lt;br /&gt;
&lt;br /&gt;
Activate site configuration, reload and start Nginx:&lt;br /&gt;
&lt;br /&gt;
ln -s /etc/nginx/sites-available/mail.mysystems.tld /etc/nginx/sites-enabled/mail.mysystems.tld&lt;br /&gt;
nginx -t&lt;br /&gt;
systemctl reload nginx&lt;br /&gt;
&lt;br /&gt;
Apache proxy for Rspamd web interface (optional, not checked!)&lt;br /&gt;
&lt;br /&gt;
Install Apache2:&lt;br /&gt;
&lt;br /&gt;
    apt install apache2&lt;br /&gt;
&lt;br /&gt;
Enable proxy module and restart Apache2:&lt;br /&gt;
&lt;br /&gt;
    a2enmod proxy&lt;br /&gt;
    a2enmod proxy_http&lt;br /&gt;
    systemctl restart apache2&lt;br /&gt;
&lt;br /&gt;
Configuration ```/etc/apache2/sites-available/mailserver.conf```:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
        ServerName mail.mysystems.tld&lt;br /&gt;
        Redirect / https://mail.mysystems.tld/&lt;br /&gt;
    &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;VirtualHost *:443&amp;gt;&lt;br /&gt;
        ServerName mail.mysystems.tld&lt;br /&gt;
        ServerPath /&lt;br /&gt;
        DocumentRoot /var/www&lt;br /&gt;
        DirectoryIndex index.html&lt;br /&gt;
&lt;br /&gt;
        SSLEngine on&lt;br /&gt;
        SSLHonorCipherOrder on&lt;br /&gt;
        SSLCertificateFile /etc/letsencrypt/live/mail.mysystems.tld/fullchain.pem&lt;br /&gt;
        SSLCertificateKeyFile /etc/letsencrypt/live/mail.mysystems.tld/privkey.pem&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
        ###&lt;br /&gt;
        ### Rspamd&lt;br /&gt;
        ###&lt;br /&gt;
&lt;br /&gt;
        RewriteEngine on&lt;br /&gt;
        RewriteRule ^/rspamd$ /rspamd/ [R]&lt;br /&gt;
        ProxyPreserveHost On&lt;br /&gt;
        ProxyPass /rspamd http://localhost:11334/&lt;br /&gt;
        ProxyPassReverse /rspamd http://localhost:11334/&lt;br /&gt;
    &amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Activate new configuration and reload Apache2&lt;br /&gt;
&lt;br /&gt;
    a2ensite mailserver&lt;br /&gt;
    systemctl reload apache2&lt;br /&gt;
&lt;br /&gt;
Access web interface via webbrowser&lt;br /&gt;
&lt;br /&gt;
You should now be able to access the Rspamd web interface via https://mail.mysystems.tld/rspamd/ . Then enter the password you chose during Rspamd configuration.&lt;br /&gt;
if Rspamd throws errors like &amp;quot;/var/lib/rspamd/ [...]: map file is unavailable for reading&amp;quot;. Just ignore them, since this is a bug. (See: https://github.com/vstakhov/rspamd/issues/1474)&lt;br /&gt;
Access Rspamd web interface via SSH tunnel (alternative to Nginx)&lt;br /&gt;
&lt;br /&gt;
If your local machine is a Linux or MAC computer, enter the following command to bind the webinterface to your local TCP port 8080:&lt;br /&gt;
&lt;br /&gt;
ssh -L 8080:localhost:11334 benutzer@mail.mysystems.tld -N&lt;br /&gt;
&lt;br /&gt;
The web interface can then be browsed via http://localhost:8080. CTRL+C cancels the connection.&lt;br /&gt;
Train Rspamd with existing spam mail (optional)&lt;br /&gt;
&lt;br /&gt;
If you have mailboxes in Maildir-format with spam e-mails and normal e-mails, you can use them to train Rspamd on some real world examples. Copy those mailbox folders to your new server and execute commands like this:&lt;br /&gt;
&lt;br /&gt;
Train e-mails in ./oldserver/var/vmail/mailboxes/*/*/mail/Spam/cur as spam:&lt;br /&gt;
&lt;br /&gt;
find ./oldserver/var/vmail/mailboxes/*/*/mail/Spam/cur -type f -exec /usr/bin/rspamc learn_spam {} \;&lt;br /&gt;
&lt;br /&gt;
Train e-mails as “ham”:&lt;br /&gt;
&lt;br /&gt;
find ./oldserver/var/vmail/mailboxes/*/*/mail/cur -type f -exec /usr/bin/rspamc learn_ham {} \;&lt;br /&gt;
find ./oldserver/var/vmail/mailboxes/*/*/mail/Sent/cur -type f -exec /usr/bin/rspamc learn_ham {} \;&lt;br /&gt;
&lt;br /&gt;
Create domains, accounts, aliases and TLS-policies in database&lt;br /&gt;
&lt;br /&gt;
Before the mailserver can be used reasonably, at least one domain and a corresponding user account must be existent. Fire up your msql command shell one more time:&lt;br /&gt;
&lt;br /&gt;
mysql&lt;br /&gt;
&lt;br /&gt;
… change to the vmail database:&lt;br /&gt;
&lt;br /&gt;
use vmail;&lt;br /&gt;
&lt;br /&gt;
Create a new domain data record&lt;br /&gt;
&lt;br /&gt;
New user accounts can only be created for already existing domains, so create a new data set for your primary domain:&lt;br /&gt;
&lt;br /&gt;
insert into domains (domain) values (&#039;mysystems.tld&#039;);&lt;br /&gt;
&lt;br /&gt;
Create a new user account&lt;br /&gt;
&lt;br /&gt;
Now that the corresponding domains exists, a new user account for this domain can be created. But there is one step left to do: Before the SQL statement for a new account is executed, we need a hash of the passwort to be used with this account. Create a new password hash in the normal Bash Shell(!) via:&lt;br /&gt;
&lt;br /&gt;
doveadm pw -s SHA512-CRYPT&lt;br /&gt;
&lt;br /&gt;
A password hash looks similar to this:&lt;br /&gt;
&lt;br /&gt;
{SHA512-CRYPT}$6$wHyJsS.doo39xoCu$KI1N4l.Vd0ZWYj5BYLI8AdK7ACwAZaM18gSy7Bko0dG2Hvli4.KfAmLk2ztFVP.R4T7oqiu7clKBehCTc4GGw0&lt;br /&gt;
&lt;br /&gt;
Now copy that hash and save it somewhere else - you’ll need it in a few moments. First, paste the following into your SQL Shell(!):&lt;br /&gt;
&lt;br /&gt;
insert into accounts (username, domain, password, quota, enabled, sendonly) values (&#039;user1&#039;, &#039;mysystems.tld&#039;, &#039;{SHA512-CRYPT}$6$wHyJsS[...]&#039;, 2048, true, false);&lt;br /&gt;
&lt;br /&gt;
The value for the password field must now be replaced with the individual hash you’ve created before. In this example, an account for “user1@mysystems.tld” is created, with a storage quota of 2 GB, and the account is able to send and receive messages.&lt;br /&gt;
Create new alias address&lt;br /&gt;
&lt;br /&gt;
Creating an alias address for another address is pretty streight forward:&lt;br /&gt;
&lt;br /&gt;
insert into aliases (source_username, source_domain, destination_username, destination_domain, enabled) values (&#039;alias&#039;, &#039;mysystems.tld&#039;, &#039;user1&#039;, &#039;mysystems.tld&#039;, true);&lt;br /&gt;
&lt;br /&gt;
This would result in a re-direction of e-mails from alias@mysystems.tld to user1@mysystems.tld. If you want to implement a something like a poor man’s mailing list, you can create multiple alias entries such as:&lt;br /&gt;
&lt;br /&gt;
team@domain.tld =&amp;gt; user1@domain.tld&lt;br /&gt;
team@domain.tld =&amp;gt; user2@domain.tld&lt;br /&gt;
team@domain.tld =&amp;gt; user3@domain.tld&lt;br /&gt;
&lt;br /&gt;
Define a new TLS policy (optional)&lt;br /&gt;
&lt;br /&gt;
TLS policies let you specify how strong a connection to another mailserver must be secured. There are different levels of security and verification:&lt;br /&gt;
&lt;br /&gt;
    none: Don’t use encryption&lt;br /&gt;
    may: Encrypt, if supported by other server. Self-signed certificates are accepted, because there is no certificate verification.&lt;br /&gt;
    encrypt: Always encrypt. Self-signed certificates are accepted, because there is no certificate verification.&lt;br /&gt;
    dane: If there are valid TLSA-records in the DNS, encryption is mandatory. The certificate is then verified via DANE. If invalid TLSA records are found, fallback is “encrypt”. If no TLSA-records are found, fallback is “may”.&lt;br /&gt;
    dane-only: Encrypted connections only. Certificate verification via DANE. No fallback to weaker methods.&lt;br /&gt;
    verify: Encrypted connections only. Certificate must be issued by an accepted CA. Hostname given in MX record must match hostname in certificate.&lt;br /&gt;
    secure: Encrypted connections only. Certificate must be issued by an accepted CA. Hostname in certificate must by domain or subdomain of e-mail domain. No DNS used.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
insert into tlspolicies (domain, policy) values (&#039;mailbox.org&#039;, &#039;dane-only&#039;);&lt;br /&gt;
&lt;br /&gt;
The “params” field is used for additional verification details, such as “match” parameters. E.g. for GMX Mail you would define:&lt;br /&gt;
&lt;br /&gt;
insert into tlspolicies (domain, policy, params) values (&#039;gmx.de&#039;, &#039;secure&#039;, &#039;match=.gmx.net&#039;);&lt;br /&gt;
&lt;br /&gt;
But why? Well, if “secure” as a mechanism is chosen, Postfix will find out the domain part of the recipient’s mail address. For GMX that could be thomas@gmx.de for example. Now Postfix would only allow connections to mail hosts, which have “gmx.de” in their hostname, such as host1.gmx.de, host2.gmx.de and so on. The problem here is, that GMX has no hosts running at “*gmx.de”. They are running at gmx.NET instead. So the “secure” policy must be extended with match=.gmx.net - otherwise connections to GMX mail servers would fail.&lt;br /&gt;
&lt;br /&gt;
You can now leave the SQL shell again by entering quit;&lt;br /&gt;
Start all the things!&lt;br /&gt;
&lt;br /&gt;
Let’s get the party started! \o/&lt;br /&gt;
&lt;br /&gt;
systemctl start dovecot&lt;br /&gt;
systemctl start postfix&lt;br /&gt;
&lt;br /&gt;
Postfix does not re-start properly after a reboot because of bug #877992. To fix this behavior, run:&lt;br /&gt;
&lt;br /&gt;
systemctl enable postfix@-&lt;br /&gt;
&lt;br /&gt;
(note the “-” at the end of the line!)&lt;br /&gt;
&lt;br /&gt;
You may want to check if everything is working fine. Enter&lt;br /&gt;
&lt;br /&gt;
tail -f /var/log/syslog&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
tail -f /var/log/mail.log&lt;br /&gt;
&lt;br /&gt;
to check if any errors occur.&lt;br /&gt;
Connect to your new mail server&lt;br /&gt;
&lt;br /&gt;
    IMAP-Server: mail.mysystems.tld | Port: 143 | STARTTLS (also use this server for domain2 und domain3!)&lt;br /&gt;
    SMTP-Server: mail.mysystems.tld | Port: 587 | STARTTLS (also use this server for domain2 und domain3!)&lt;br /&gt;
    (optional Managesieve: mail.mysystems.tld | Port: 4190 | STARTTLS) (also use this server for domain2 und domain3!)&lt;br /&gt;
    Username: Complete(!) e-mail address&lt;br /&gt;
    Password: … you should know ;-)&lt;br /&gt;
&lt;br /&gt;
The first login might take a few moments.&lt;br /&gt;
Login data for Thunderbird&lt;br /&gt;
Login data for Thunderbird&lt;br /&gt;
Test your spam filter&lt;br /&gt;
&lt;br /&gt;
Send an e-mail with the following body content to one of your new mailboxes:&lt;br /&gt;
&lt;br /&gt;
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X&lt;br /&gt;
&lt;br /&gt;
This e-mail should never arrive at its destination and Rspamd should show a rejected e-mail in its history log.&lt;br /&gt;
Did you like my how-to?&lt;br /&gt;
&lt;br /&gt;
If you like this how-to, you maybe want to appreciate it by giving some dollars?&lt;br /&gt;
&lt;br /&gt;
As you may know, developing, writing and testing a how-to is much work - especially for more complex setups like a mail server. If you want to say &amp;quot;thanks&amp;quot;, help me pay my test servers or just keep me motivated, please consider donating a few dollars. :-)&lt;br /&gt;
&lt;br /&gt;
Support my work&lt;br /&gt;
&lt;br /&gt;
Thanks a lot! :-)&lt;br /&gt;
Q&amp;amp;A&lt;br /&gt;
“Am I allowed to copy / republish your how-to?”&lt;br /&gt;
&lt;br /&gt;
No, please don’t to that. You can keep private copies, if you want.&lt;br /&gt;
“Is there a web interface for managing user accounts / domains / … ?”&lt;br /&gt;
&lt;br /&gt;
Currently there is only one finished web interface by Andreas Bresch: https://github.com/Andreas-Bresch/vmailManage/&lt;br /&gt;
Changelog&lt;br /&gt;
&lt;br /&gt;
    (Published on 04.08.2017)&lt;br /&gt;
&lt;br /&gt;
    2017-08-29&lt;br /&gt;
        vmail MySQL user gets “select” permissions instead of “all” permissions&lt;br /&gt;
        master.cf: More services run in chroot for better security. “mua” parameters to submission part and to main.cf&lt;br /&gt;
&lt;br /&gt;
    2017-08-31&lt;br /&gt;
        Added: Copy dkim_signing.conf to arc.conf to prevent error cannot load dkim key /var/lib/rspamd/arc/domain.tld.arc.key&lt;br /&gt;
        Added: non_smtpd_milters = inet:localhost:11332 to DKIM-sign e-mails from mailserver itself, too.&lt;br /&gt;
&lt;br /&gt;
    2017-10-25&lt;br /&gt;
        Deprecated Dovecot-Antispam replaced by ImapSieve + two more sieve scripts.&lt;br /&gt;
&lt;br /&gt;
    2017-10-27&lt;br /&gt;
        Removes deprecated ADSP and adds DMARC section.&lt;br /&gt;
&lt;br /&gt;
    2017-11-06&lt;br /&gt;
        Workaround concerning Bug #877992 added.&lt;br /&gt;
&lt;br /&gt;
    2017-11-12&lt;br /&gt;
        Added hint for “Mailman” web based management GUI.&lt;br /&gt;
&lt;br /&gt;
    2017-12-05&lt;br /&gt;
        Added Apache2 configuration for Rspamd proxy&lt;br /&gt;
&lt;br /&gt;
    2018-01-19&lt;br /&gt;
        dovecot.conf: Removed obsolete settings ssl_dh_parameters_length and ssl_protocols&lt;br /&gt;
        Added /etc/rspamd/local.d/classifier-bayes.conf&lt;br /&gt;
        Minor style improvements / fixes&lt;br /&gt;
        Added warning concerning Ubuntu Server&lt;br /&gt;
&lt;br /&gt;
    2018-01-20&lt;br /&gt;
        Added hint: Henrik Halbritter’s “MailAdmin”&lt;br /&gt;
&lt;br /&gt;
    2018-01-22&lt;br /&gt;
        Added Dovecot PPA for Ubuntu Server&lt;br /&gt;
&lt;br /&gt;
    2018-02-02&lt;br /&gt;
        tls_preempt_cipherlist = yes added to Postfix main.cf&lt;br /&gt;
&lt;br /&gt;
    2018-03-30&lt;br /&gt;
        Added hint: You have to add the DKIM record for every mail domain!&lt;br /&gt;
&lt;br /&gt;
    2019-03-02&lt;br /&gt;
        Fixes learn-ham behavior&lt;br /&gt;
&lt;br /&gt;
    #Mailserver#E-Mail#Linux#Debian#Dovecot#Postfix#Rspamd&lt;br /&gt;
&lt;br /&gt;
2017-08-07&lt;br /&gt;
Consider a donation if this article was useful to you. :-)&lt;br /&gt;
&lt;br /&gt;
    ImprintDonateAtom Feed&lt;/div&gt;</summary>
		<author><name>31.221.135.161</name></author>
	</entry>
</feed>