I use a very good and detailed guide created by Thomas Leister.
Since I have a Gentoo Linux running I want to explain within this article how you can use this guide for Gentoo Linux.
Therefore, please read this guide first to get an overview of all the stuff.
Requirements
You have to had a are running a Gentoo Linux with working internet connection and you must be root.
Goal
At the end we will have a running Gentoo Server with:
Dovecot
Postfix
MySQL
Rspamd
Postfix-Admin
Mail-Server
Certifications
Database
We will use MariaDB as Database (https://wiki.gentoo.org/wiki/MariaDB):
If you do not have mariadb installed already you have to configure it, therefore, we can use a predefined configuration helper:
Start database and add them to your autostart:
Open MySQL Root Shell to perform SQL commands:
The first step is to create a database for our mail-service, called vmail:
Create a user who can access the database using vmaildbpass as password (please use a secure one):
Next step we have to use our database vmail:
** CHECK IF YOU NEED THIS … SINCE WE WILL USE POSTFIX-ADMIN **
Our Mail-setup will use 4 different tables. Therefore, we have to create them:
Domain Table
Account Table
Alias Table
TLS Policy-Tabelle
Vmail User
We will use /home/vmail as mail-server file storage directory (mailboxes, filter-scripts, …):
vmail-Systembenutzer erstellen:
vmail Unterverzeichnisse erstellen:
/var/vmail an vmail-User übereignen und Verzeichnisrechte passend setzen:
Dovecot
Please ensure that at least the following USE-flags are enabled.
Configuration
All configuration files are located at /etc/dovecot/.
/etc/dovecot/dovecot.conf
/etc/dovecot/conf.d/10-ssl.conf
/etc/dovecot/conf.d/10-mail.conf
If you want maildirs to use hierarchical directories, such as:
Maildir/folder/
Maildir/folder/subfolder/
Therefore, we have to add LAYOUT=fs:
/etc/dovecot/conf.d/10-master.conf
/etc/dovecot/conf.d/20-managesieve.conf
/etc/dovecot/conf.d/20-imap.conf
/etc/dovecot/conf.d/20-lmtp.conf
/etc/dovecot/conf.d/auth-sql.conf
/etc/dovecot/conf.d/15-mailboxes.conf
/etc/dovecot/conf.d/90-sieve.conf
/etc/dovecot/dovecot-sql.conf
Since dovecot-sql.confcontains sensitive data we secure the file:
Global Sieve Filter Script for Spam Detection
Create the file /home/vmail/sieve/global/spam-global.sieve:
This script will move all emails taged with Spam-Flag header into Spam the folder.
Scripts for Spam Improvement (Rspamd)
/home/vmail/sieve/global/learn-spam.sieve
/home/vmail/sieve/global/learn-ham.sieve
Compile Sieve files: will generate *.svbin files
Postfix - Installation and Configuration
Ensure you have the use flag mysql enabled.
Mail-Queue Settings
TLS Settings
Outgoing SMTP-Connections (Postfix as sender)
Incoming SMTP-Connections
Local mail delivery using Dovecot
Spam-filter and DKIM-Sig via Rspamd
Server Restrictions for clients, receiver and relaying
Settings, Postfix as Relay (for clients)
Bedingungen, damit Postfix ankommende E-Mails als Empfängerserver entgegennimmt (zusätzlich zu relay-Bedingungen)
check_recipient_access prüft, ob ein account sendonly ist
Bedingungen, die SMTP-Clients erfüllen müssen (sendende Server)
Wenn fremde Server eine Verbindung herstellen, müssen sie einen gültigen Hostnamen im HELO haben.
Clients blockieren, wenn sie versuchen zu früh zu senden
Restrictions für MUAs (Mail user agents)
Postscreen Filter
Postscreen Whitelist / Blocklist
Verbindungen beenden, wenn der fremde Server es zu eilig hat
DNS blocklists
MySQL Abfragen
Sonstiges
Maximale Größe der gesamten Mailbox (soll von Dovecot festgelegt werden, 0 = unbegrenzt)
Maximale Größe eingehender E-Mails in Bytes (50 MB)
Keine System-Benachrichtigung für Benutzer bei neuer E-Mail
Nutzer müssen immer volle E-Mail Adresse angeben - nicht nur Hostname