Setting up a Secure Mail Server
- security
- mailserver
- DKIM
- Rspamd
- MariaDB
- Roundcube
- dmarc
In this tutorial you will learn how to configure a mail server that uses DKIM, Rspamd and MariaDB to deliver mails securely. You will install a Roundcube webmail interface to be able to read your mails directly from your browser.
We recommend you follow this tutorial using a Production-Optimized Instance.
You may need certain IAM permissions to carry out some actions described on this page. This means:
- you are the Owner of the Scaleway Organization in which the actions will be carried out, or
- you are an IAM user of the Organization, with a policy granting you the necessary permission sets
- You have an account and are logged into the Scaleway console
- You have configured your SSH key
- You have an Instance running Ubuntu Bionic Beaver or later
- You have a domain or subdomain configured to point to the IP address of your Instance
- You have enabled the SMTP ports to send emails from your Instance
Pre-work
Before you continue with this tutorial, some configuration is required to make sure your mail server will be working.
- To ensure that other servers will accept mails sent from your Instance a valid reverse DNS within your own domain name (for example
mail.domain.com
) must be configured. - The SMTP ports have been unlocked in the security group of the server.
- Start by updating your system to make sure you have the latest software releases installed:
apt update && apt upgrade
- Before starting the installation of the mail server, make sure that there is no other mail software already installed:
service sendmail stop; update-rc.d -f sendmail removeTip:
If you receive a message
Failed to stop sendmail.service: Unit sendmail.service not loaded.
you can ignore it. It will only tell you that sendmail has not been installed, so it cannot be removed.
Installing PostfixAdmin
All mailboxes will belong to virtual users. To manage mailboxes, we need one system user which will be the owner of all mailboxes and will be used by all virtual users to access their emails on the server. The home directory of the user will be /var/mail/vmail
and all mailboxes will be stored in that directory:
groupadd -g 5000 vmailuseradd -u 5000 -g vmail -s /usr/sbin/nologin -d /var/mail/vmail -m vmail
As PostfixAdmin is a PHP application, a web server is required. We will use Nginx with PHP7.2 and MariaDB:
apt install nginx mariadb-server php-fpm php-cli php-imap php-json php-mysql php-opcache php-mbstring php-readline
-
Set a root password for MariaDB:
mysql_secure_installationThe setup tool will ask you the following questions:
Enter current password for root (enter for none):
- Press EnterSet root password? [Y/n]
- Type YNew password:
- Enter the password for the root userRe-enter new password:
- Repeat the passwordRemove anonymous users? [Y/n]
- TypeY
Disallow root login remotely? [Y/n]
- TypeY
Remove test database and access to it? [Y/n]
- TypeY
Reload privilege tables now? [Y/n]
- TypeY
-
Download and unpack PostfixAdmin. The latest version at the time of writing of this tutorial is version 3.3.8:
wget https://downloads.sourceforge.net/project/postfixadmin/postfixadmin-3.3.8/PostfixAdmin%203.3.8.tar.gztar xzf postfixadmin*.tar.gz -
Move PostfixAdmin into the directory
/var/www/postfixadmin
:mv postfixadmin-*/ /var/www/postfixadminrm -f PostfixAdmin*.tar.gzmkdir /var/www/postfixadmin/templates_c -
Change the ownership of the directory to the
www-data
user, as Nginx and PHP are using it:chown -R www-data: /var/www/postfixadmin -
PostfixAdmin will use a MySQL database to store information. Connect to your MariaDB Server to create a new database and user:
mysql -u root -p -
Create the database, remember to replace
your_secret_password
with a password for thepostfixadmin
user:CREATE DATABASE postfixadmin;GRANT ALL ON postfixadmin.* TO 'postfixadmin'@'localhost' IDENTIFIED BY 'your_secret_password';FLUSH PRIVILEGES;EXIT; -
Create a configuration file
/var/www/postfixadmin/config.local.php
and open it in a text editor. Copy the following content into it:<?php$CONF['configured'] = true;$CONF['database_type'] = 'mysqli';$CONF['database_host'] = 'localhost';$CONF['database_user'] = 'postfixadmin';$CONF['database_password'] = 'your_secret_password';$CONF['database_name'] = 'postfixadmin';$CONF['default_aliases'] = array ('abuse' => 'abuse@example.com','hostmaster' => 'hostmaster@example.com','postmaster' => 'postmaster@example.com','webmaster' => 'webmaster@example.com');$CONF['fetchmail'] = 'NO';$CONF['show_footer_text'] = 'NO';$CONF['quota'] = 'YES';$CONF['domain_quota'] = 'YES';$CONF['quota_multiplier'] = '1024000';$CONF['used_quotas'] = 'YES';$CONF['new_quota_table'] = 'YES';$CONF['aliases'] = '0';$CONF['mailboxes'] = '0';$CONF['maxquota'] = '0';$CONF['domain_quota_default'] = '0';?>Note:Remember to replace
your_secret_password
with the password for the database user.The configuration defines the database type, login credentials, default aliases, disabled fetchmail and enabled quota.
-
Now run the following script to install the database schema:
sudo -u www-data php /var/www/postfixadmin/public/upgrade.phpAs the database is ready now, it is possible to create the first superadmin from the CLI tools:
bash /var/www/postfixadmin/scripts/postfixadmin-cli admin addEnter the email address of the admin, and answer the questions of the CLI.
-
Create a Nginx configuration file for your domain. Open the file
/etc/nginx/sites-enabled/mail.example.com.conf
and paste the following configuration. Do not forget to edit theserver_name
to your domain name:server {listen 80;server_name mail.example.com;root /var/www;location / {try_files $uri $uri/ /index.php;}location /postfixadmin {index index.php;try_files $uri $uri/ /postfixadmin/public/login.php;}location ~* \.php$ {fastcgi_split_path_info ^(.+?\.php)(/.*)$;if (!-f $document_root$fastcgi_script_name) {return 404;}fastcgi_pass unix:/run/php/php7.4-fpm.sock;fastcgi_index index.php;include fastcgi_params;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;}} -
Restart Nginx to activate the configuration:
service nginx restart -
To secure the communication with the web server, we use Let’s Encrypt to get a free SSL certificate:
apt install python3-certbot-nginxcertbot --nginx
Installation of Postfix and Dovecot
-
Install the required software. You can install all required packages with one command with apt:
apt install postfix postfix-mysql dovecot-imapd dovecot-lmtpd dovecot-pop3d dovecot-mysqlYou will be asked some questions during the installation:
- For server type choose
Internet Site
- For mail name, enter the FQDN of the server (for example:
mail.example.com
)
We use virtual users in our configuration. Therefore, we have to create the configuration files for postfix to use the database we have created previously.
- For server type choose
-
Start by creating a directory to store the files:
mkdir -p /etc/postfix/sql -
Create and open the file
/etc/postfix/sql/mysql_virtual_domains_maps.cf
in a text editor and put the following content in it:user = postfixadminpassword = your_secret_passwordhosts = 127.0.0.1dbname = postfixadminquery = SELECT domain FROM domain WHERE domain='%s' AND active = '1' -
Create and open the file
/etc/postfix/sql/mysql_virtual_alias_maps.cf
in a text editor and put the following content in it:user = postfixadminpassword = your_secret_passwordhosts = 127.0.0.1dbname = postfixadminquery = SELECT goto FROM alias WHERE address='%s' AND active = '1' -
Create and open the file
/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
in a text editor and put the following content in it:user = postfixadminpassword = your_secret_passwordhosts = 127.0.0.1dbname = postfixadminquery = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1' -
Create and open the file
/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf
in a text editor and put the following content in it:user = postfixadminpassword = your_secret_passwordhosts = 127.0.0.1dbname = postfixadminquery = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1' -
Create and open the file
/etc/postfix/sql/mysql_virtual_mailbox_maps.cf
in a text editor and put the following content in it:user = postfixadminpassword = your_secret_passwordhosts = 127.0.0.1dbname = postfixadminquery = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1' -
Create and open the file
/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
in a text editor and put the following content in it:user = postfixadminpassword = your_secret_passwordhosts = 127.0.0.1dbname = postfixadminquery = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1' -
Once the MySQL configuration files are created, update the configuration of Postfix:
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf"postconf -e "virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf"postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf"Note:The
postconf
command can be used to display the actual configuration, change configuration values, or display other configuration information about the Postfix mail system.Local delivery will be handled by Dovecot’s local delivery agent. It will take mail from an MTA (Postfix) and deliver it to a local user’s mailbox.
postconf -e "virtual_transport = lmtp:unix:private/dovecot-lmtp" -
Configure TLS parameters by using the Let’s encrypt SSL certificate:
postconf -e 'smtp_tls_security_level = may'postconf -e 'smtpd_tls_security_level = may'postconf -e 'smtp_tls_note_starttls_offer = yes'postconf -e 'smtpd_tls_loglevel = 1'postconf -e 'smtpd_tls_received_header = yes'postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem'postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem' -
Configure the authenticated SMTP settings:
postconf -e 'smtpd_sasl_type = dovecot'postconf -e 'smtpd_sasl_path = private/auth'postconf -e 'smtpd_sasl_local_domain ='postconf -e 'smtpd_sasl_security_options = noanonymous'postconf -e 'broken_sasl_auth_clients = yes'postconf -e 'smtpd_sasl_auth_enable = yes'postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination' -
Enable the TLS/SSL and submission ports in the Postfix configuration file. Open the file
/etc/postfix/master.cf
with a text editor, uncomment the submission and smtps sections as following. Make sure that there is a whitespace in front of the-o
as it is required:submission inet n - y - - smtpd-o syslog_name=postfix/submission-o smtpd_tls_security_level=encrypt-o smtpd_sasl_auth_enable=yes# -o smtpd_reject_unlisted_recipient=no-o smtpd_client_restrictions=permit_sasl_authenticated,reject# -o smtpd_helo_restrictions=$mua_helo_restrictions# -o smtpd_sender_restrictions=$mua_sender_restrictions# -o smtpd_recipient_restrictions=# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject-o milter_macro_daemon_name=ORIGINATINGsmtps inet n - y - - smtpd-o syslog_name=postfix/smtps-o smtpd_tls_wrappermode=yes-o smtpd_sasl_auth_enable=yes# -o smtpd_reject_unlisted_recipient=no-o smtpd_client_restrictions=permit_sasl_authenticated,reject# -o smtpd_helo_restrictions=$mua_helo_restrictions# -o smtpd_sender_restrictions=$mua_sender_restrictions# -o smtpd_recipient_restrictions=# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject-o milter_macro_daemon_name=ORIGINATING -
Restart postfix to take the modifications into effect:
service postfix restart -
Edit the file
/etc/dovecot/dovecot-sql.conf.ext
as follows:driver = mysqlconnect = host=127.0.0.1 dbname=postfixadmin user=postfixadmin password=your_secret_passworddefault_pass_scheme = MD5-CRYPTiterate_query = SELECT username AS user FROM mailboxuser_query = SELECT CONCAT('/var/mail/vmail/',maildir) AS home, \CONCAT('maildir:/var/mail/vmail/',maildir) AS mail, \5000 AS uid, 5000 AS gid, CONCAT('*:bytes=',quota) AS quota_rule \FROM mailbox WHERE username = '%u' AND active = 1password_query = SELECT username AS user,password FROM mailbox \WHERE username = '%u' AND active='1' -
Edit the file
/etc/dovecot/conf.d/10-mail.conf
with the required information as shown below:...mail_location = maildir:/var/mail/vmail/%d/%n...mail_uid = vmailmail_gid = vmail...first_valid_uid = 5000last_valid_uid = 5000...mail_privileged_group = mail...mail_plugins = quota... -
Modify the information in the file
/etc/dovecot/conf.d/10-auth.conf
as following:...disable_plaintext_auth = yes...auth_mechanisms = plain login...#!include auth-system.conf.ext!include auth-sql.conf.ext... -
Edit the file
/etc/dovecot/conf.d/10-master.conf
as following:...service lmtp {unix_listener /var/spool/postfix/private/dovecot-lmtp {mode = 0600user = postfixgroup = postfix}...}...service auth {...unix_listener auth-userdb {mode = 0600user = vmailgroup = vmail}...unix_listener /var/spool/postfix/private/auth {mode = 0666user = postfixgroup = postfix}...}...service auth-worker {user = vmail}...service dict {unix_listener dict {mode = 0660user = vmailgroup = vmail}}... -
Edit the file
/etc/dovecot/conf.d/10-ssl.conf
as following:...ssl = yes...ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pemssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pemssl_dh = </etc/ssl/certs/dhparam.pem...ssl_cipher_list = EECDH+AES:EDH+AES+aRSA...ssl_prefer_server_ciphers = yes... -
Add the following line to the file
/etc/dovecot/conf.d/20-imap.conf
...protocol imap {...mail_plugins = $mail_plugins imap_quota...}... -
Edit the file
/etc/dovecot/conf.d/20-lmtp.conf
as following:...protocol imap {postmaster_address = postmaster@example.commail_plugins = $mail_plugins}... -
Add a spam folder in the file
/etc/dovecot/conf.d/15-mailboxes.conf
:...mailbox Drafts {special_use = \Drafts}mailbox Spam {special_use = \Junkauto = subscribe}mailbox Junk {special_use = \Junk}... -
Configure Dovecot to connect to the MySQL database to manage the quotas, either per domain or per user. It will send a notification by email once the mailbox of a user has reached a certain level of saturation. Edit the file
/etc/dovecot/conf.d/90-quota.conf
:quota = dict:User quota::proxy::sqlquotaquota_rule = *:storage=5GBquota_rule2 = Trash:storage=+100Mquota_grace = 10%%quota_exceeded_message = Quota exceeded, please contact your system administrator.quota_warning = storage=100%% quota-warning 100 %uquota_warning2 = storage=95%% quota-warning 95 %uquota_warning3 = storage=90%% quota-warning 90 %uquota_warning4 = storage=85%% quota-warning 85 %u}service quota-warning {executable = script /usr/local/bin/quota-warning.shuser = vmailunix_listener quota-warning {group = vmailmode = 0660user = vmail}}dict {sqlquota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext -
Make sure your MySQL credentials are correct then edit the file
/etc/dovecot/dovecot-dict-sql.conf.ext
and add the following content:...connect = host=127.0.0.1 dbname=postfixadmin user=postfixadmin password=your_secret_password...map {pattern = priv/quota/storagetable = quota2username_field = usernamevalue_field = bytes}map {pattern = priv/quota/messagestable = quota2username_field = usernamevalue_field = messages}...# map {# pattern = shared/expire/$user/$mailbox# table = expires# value_field = expire_stamp## fields {# username = $user# mailbox = $mailbox# }# }... -
Create the following script, which sends a warning to a user that reaches the capacity limits of his mailbox. Edit the file
/usr/local/bin/quota-warning.sh
:#!/bin/shPERCENT=$1USER=$2cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=dict:User quota::noenforcing:proxy::sqlquota"From: postmaster@example.comSubject: Quota warningYour mailbox is $PERCENT% full. Do not forget to make a backup of old messages to remain able to receive mails.EOF -
Make the script executable:
chmod +x /usr/local/bin/quota-warning.shAnd restart dovecot:
service dovecot restart
Your mail server is now ready to be used, and you can create mailboxes at http://your_servers_ip/postfixadmin
Installing Rspamd
To protect yourself from spam and to increase the trust level of your mails, we use Rspamd and create DKIM and DMARC DNS records.
Installing Redis
Redis is used by Rspamd as a storage and caching system. It can easily be installed with apt:
apt install redis-server
Installing Rspamd
- Add the repository of Rspamd to your apt sources with the following command:
wget -O- https://rspamd.com/apt-stable/gpg.key | apt-key add -echo "deb http://rspamd.com/apt-stable/ $(lsb_release -cs) main" | tee -a /etc/apt/sources.list.d/rspamd.list
- Then update your apt cache and install the tool:
apt updateapt install rspamd
Configuring Rspamd
-
Once the installation has finished, create the config files for Rspamd in the directory
/etc/rspamd/local.d/local.d/
.The file
/etc/rspamd/local.d/worker-normal.inc
contains information about the port on which Rspamd listens. The default port is 11333, bind it to your localhost by adding the following line to the file:bind_socket = "127.0.0.1:11333"; -
Configure a proxy between Postfix and Rspamd, it listens on port 11332 and uses milter to communicate between the two tools. Edit the file
/etc/rspamd/local.d/worker-proxy.inc
-
Set a password for the worker. To generate an encrypted password, run the following command:
rspamadm pw --encrypt -p your_secret_passwordNote:Remember to replace
your_secret_password
with your own passwordYou will see an output like the following:
rspamadm pw --encrypt -p your_secret_password$2$93qin9nkifzjpr7taqhs9guua888tnny$dnys6um6xm1gb1amgnz9hocuz7grxuk5z9yjw87psrk6yu641oiy -
Edit the file
/etc/rspamd/local.d/worker-controller.inc
and put the encrypted password into it:password = "$2$93qin9nkifzjpr7taqhs9guua888tnny$dnys6um6xm1gb1amgnz9hocuz7grxuk5z9yjw87psrk6yu641oiy";Configure redis to be used with rspamd by editing the file
/etc/rspamd/local.d/classifier-bayes.conf
:servers = "127.0.0.1";backend = "redis"; -
Set the milter headers in the file
/etc/rspamd/local.d/milter_headers.conf
:use = ["x-spamd-bar", "x-spam-level", "authentication-results"]; -
Restart Rspamd:
service rspamd restart -
Add a proxy in the Nginx configuration file (for example:
/etc/nginx/sites-enabled/mail.example.com.conf
):...location /rspamd {proxy_pass http://127.0.0.1:11334/;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}... -
Restart Nginx:
service nginx restart
You can access the web interface of Rspamd now at: http://your_servers_ip/rspamd. To authenticate use the password you have set with the rspamadm pw
command.
Configuring Postfix
To use Rspamd with Postfix, the configuration has to be updated with postconf
:
postconf -e "milter_protocol = 6"postconf -e "milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}"postconf -e "milter_default_action = accept"postconf -e "smtpd_milters = inet:127.0.0.1:11332"postconf -e "non_smtpd_milters = inet:127.0.0.1:11332"
Restart postfix to take the changes into effect:
service postfix restart
Configuring Dovecot
Dovecot is already installed on the server, add the sieve
filtering module and integrate it with Rspamd.
- Install sieve via apt:
apt install dovecot-sieve dovecot-managesieved
- Open the file
/etc/dovecot/conf.d/20-lmtp.conf
and edit it as following:...protocol lmtp {postmaster_address = postmaster@example.commail_plugins = $mail_plugins sieve}... - Open the file
/etc/dovecot/conf.d/20-imap.conf
and edit it as following:...protocol imap {...mail_plugins = $mail_plugins imap_quota imap_sieve...}... - Edit the file
/etc/dovecot/conf.d/20-managesieve.conf
as following:...service managesieve-login {inet_listener sieve {port = 4190}}...service managesieve {process_limit = 1024}... - Open and edit the file
/etc/dovecot/conf.d/90-sieve.conf
as following:plugin {...# sieve = file:~/sieve;active=~/.dovecot.sievesieve_plugins = sieve_imapsieve sieve_extprogramssieve_before = /var/vmail/mail/sieve/global/spam-global.sievesieve = file:/var/vmail/mail/sieve/%d/%n/scripts;active=/var/vmail/mail/sieve/%d/%n/active-script.sieveimapsieve_mailbox1_name = Spamimapsieve_mailbox1_causes = COPYimapsieve_mailbox1_before = file:/var/vmail/mail/sieve/global/report-spam.sieveimapsieve_mailbox2_name = *imapsieve_mailbox2_from = Spamimapsieve_mailbox2_causes = COPYimapsieve_mailbox2_before = file:/var/vmail/mail/sieve/global/report-ham.sievesieve_pipe_bin_dir = /usr/binsieve_global_extensions = +vnd.dovecot.pipe....} - Restart the
dovecot
service and create a directory for the sieve scripts:service dovecot restartmkdir -p /var/vmail/mail/sieve/global - Create a global sieve filter in the file
/var/vmail/mail/sieve/global/spam-global.sieve
. It will move emails marked as spam directly to the spam folder:require ["fileinto","mailbox"];if anyof(header :contains ["X-Spam-Flag"] "YES",header :contains ["X-Spam"] "Yes",header :contains ["Subject"] "*** SPAM ***"){fileinto :create "Spam";stop;} - Create a script, named
/var/vmail/mail/sieve/global/report-spam.sieve
, that will be triggered each time you manually move an email into the spam folder:require ["vnd.dovecot.pipe", "copy", "imapsieve"];pipe :copy "rspamc" ["learn_spam"]; - Create a script, named
/var/vmail/mail/sieve/global/report-ham.sieve
, that will be triggered each time when you move an email out of the spam folder:require ["vnd.dovecot.pipe", "copy", "imapsieve"];pipe :copy "rspamc" ["learn_ham"]; - Compile the sieve scripts and set permissions:
sievec /var/vmail/mail/sieve/global/spam-global.sievesievec /var/vmail/mail/sieve/global/report-spam.sievesievec /var/vmail/mail/sieve/global/report-ham.sievechown -R vmail: /var/vmail/mail/sieve/
Creating DKIM keys
DomainKeys Identified Mail (DKIM) is an email authentication method designed to detect email spoofing. It allows the receiving server to verify the origin of an email by affixing a digital signature to it. Verification of the signature is carried out using the signer’s public key published in the DNS. It can be used to detect fraudulent emails.
-
Create a new directory to store the DKIM key and generate a new DKIM key pair by using the
rspamadm
utility. In the following example we usemail
as a DKIM selector. It will generate a key pair that can be used for all domains handled by the mail server.mkdir /var/lib/rspamd/dkim/rspamadm dkim_keygen -b 2048 -s mail -k /var/lib/rspamd/dkim/mail.key > /var/lib/rspamd/dkim/mail.pubYou will find two files in the directory:
mail.key
- The privatse key filemail.pub
- The public key file
-
Create a new file
/etc/rspamd/local.d/dkim_signing.conf
to tell Rspamd where to look for the DKIM key and the selector name. The last line will enable DKIM signing for alias sender addresses:selector = "mail";path = "/var/lib/rspamd/dkim/$selector.key";allow_username_mismatch = true; -
Rspamd supports also ARC signatures, use the same configuration file and copy it
cp /etc/rspamd/local.d/dkim_signing.conf /etc/rspamd/local.d/arc.conf -
Restart Rspamd:
service rspamd restart
DNS settings
To sign your mails with DKIM, you have to add the public key to your DNS zone.
-
Retrieve the key:
cat /var/lib/rspamd/dkim/mail.pubAn output like the following one will display:
mail._domainkey IN TXT ( "v=DKIM1; k=rsa; ""p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxzllrHkbUwSR24B6iG+TgNTOU43lZhTPJemo8PKXkgaVppGJ57tlWOe9U321Qk+Ksk9qoukR4f39TCMQdAgtEPFpWSBWJJE9C2SmNz38SmhTC0AkvIzBxCdatitK2aWjHq4s9bsoQ1gIQlXKM+V7GbN2LFCBfvAU7ElBQk+QG2DuxGD/XNDLQWloYEWcqkUfxlHr0znoY86jkglVZ""nhi/cAoE0SbzjphCtibT9T1w6AztxV1yK2VTJPpBFdtAsP1Sa3GDbTn0HATHUJI8eOIXtFcIBbYisiOIWjisE3TXFpvkS69Q0gvxVFYDnftLvsf5AticeygdMOVbK1o3T4Z7QIDAQAB") ;
You can add the information as a TXT
record in the DNS zone of your domain.
Installing Roundcube Webmail
To comfortably read your mails directly within your web browser, we will install a Roundcube web mail interface.
-
Start by installing all PHP dependencies:
apt install php-intl php-mail-mime php-net-smtp php-net-socket php-pear php-xml php-intl php-xml php-gd php-gd php-imagick -
Log into your MariaDB server and create a MySQL database for Roundcube:
mysql -u root -pCREATE DATABASE roundcubemail;GRANT ALL ON roundcubemail.* TO 'roundcube'@'localhost' IDENTIFIED BY 'your_secret_password';FLUSH PRIVILEGES;\q -
Download Roundcube, unpack it and move it into the web directory:
wget https://github.com/roundcube/roundcubemail/releases/download/1.6.1/roundcubemail-1.6.1-complete.tar.gztar xzf roundcubemail-1.6.-complete.tar.gzmv roundcubemail-1.6.1 /var/www/webmailrm roundcubemail-1.6.1-complete.tar.gz -
Change the ownership of the folder and all files in it to the www-data user:
chown -R www-data: /var/www/webmail -
Edit the Nginx configuration (
/etc/nginx/sites-enabled/mail.example.com
) of your server and add the information for the Roundcube directory:...location /webmail {index index.php;try_files $uri $uri/ /webmail/index.php;}location ~ ^/webmail/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {deny all;}location ~ ^/webmail/(bin|SQL|config|temp|logs)/ {deny all;}... -
Restart Nginx:
service nginx restart -
Launch installation from
https://your_server_ip/webmail/installer/
and enter all the required information. -
Remove the installer for security reasons:
rm -rf /var/www/roundcubemail/installer