
This tutorial demonstrates a full-featured email server running on OpenBSD using OpenSMTPD, Dovecot, Rspamd, and RainLoop. OpenSMTPD is the default mail server for OpenBSD. Choose a Vultr Compute Cloud instance with plenty of storage for the expected number of users.
Verify the server's outbound port status.
Set up your user account to perform tasks as root.
Set up the package repository for OpenBSD.
Add the required packages.
By default, OpenSMTPD only listens on localhost. It must be explicitly configured to listen on external interfaces. It should be configured to use virtual users instead of system users for security.
Backup the default smtpd.conf file and create a new one from scratch.
Create a new smtpd.conf as shown below. Replace example.com with your domain. This initial configuration does not activate the rspamd filter while testing OpenSMTP. The spam filter will be activated later.
OpenSMTPD and Dovecot can share an authentication database. This database resembles the system password file in format, with two extra fields for Dovecot. The two special fields define the virtual home directory and the mail location. Passwords are in blowfish format. This tutorial creates three example users.
Generate the passwords and concatenate them to the /etc/mail/credentials file.
The output looks similar to this:
Edit /etc/mail/credentials to add the required fields. Each line maps to a system account, vmail, with UID and GID of 2000. Replace example.com with your domain. Replace the example passwords with the passwords you generated in the previous step. The virtual user name is the complete email address.
Set /etc/mail/credentials permissions to read-only for _smtpd and _dovecot system users.
Create the vmail system user, group, and home directory.
When you create the vmail system user, you will receive the following warning: useradd: Warning: home directory '/var/vmail' doesn't exist, and -m was not specified. This is expected. This avoids cluttering the directory with dot files from /etc/skel. They are not required because the vmail account does not allow login.
Create /etc/mail/virtuals to define the valid email addresses.
The first four lines assign john@example.com aliases for abuse, hostmaster, postmaster, and webmaster.
The last three lines map the email addresses to the vmail account. OpenSMTPD will deliver the messages to /var/vmail/example.com/<user>.
Mail delivery attempted for addresses not defined in this file will be bounced with a Delivery Status Notification.
This example uses a self-signed certificate. Use a valid signed certificate if you have one. When prompted for the common name, be sure it matches the FQDN of the server. This example uses mail.example.com.
Use the OpenSMTPD configuration syntax checker. If no problems are found, restart the smtpd daemon.
From an outside mail account, send a test email to one of the users.
OpenSMTPD will create the maildir folder structure below /var/vmail and deliver the mail to /var/vmail/example.com/<username>/new.
As the root user, browse to this location and verifiy you have a file named similar to this: 1576339842.4d64757b.example.com:2,.
Review the contents of the file, including all of the mail headers, to verify the email delivery works properly.
Dovecot requires the ability to have a larger number of files open for reading and writing than the default class allows. Failing to do this will cause errors that are difficult to troubleshoot.
Define a login class for the Dovecot daemon. At the bottom of /etc/login.conf add the following lines.
Create /etc/dovecot/local.conf.
There is a bug in Dovecot where the ssl_cert and ssl_key settings do not get overridden in the local.conf file so we have to comment them out. If you miss this step, Dovecot will fail to start correctly.
Edit /etc/dovecot/conf.d/10-ssl.conf as shown.
Sieve scripts train Rspamd on spam and ham. Moving email into and out of the junk folder triggers an event to train Rspamd.
These files are located at /usr/local/lib/dovecot/sieve.
Create the report-ham.sieve file.
Create the report-spam.sieve file.
Compile the files.
Create the following two shell scripts in /usr/local/lib/dovecot/sieve
Add the following to sa-learn-ham.sh
Add the following to sa-learn-spam.sh
Make the files executable.
Enable and start Dovecot.
Check that Dovecot started properly.
Verify Dovecot can correctly read /etc/mail/credentials
Verify a mail user can log in.
This is a basic Rspamd configuration, refer to the offical documentation for more details. This example creates a definition for our domain to enable DKIM signing.
Create a public/private keypair in /etc/mail/dkim and set the correct permissions.
Create a DNS record for DKIM containing the public key. Refer to your DNS provider for details of how to create a DKIM record. Copy the contents from /etc/mail/dkim/public.key and paste it after the p= part of the DKIM record as shown below. Note this example also creates an SPF record.
Create a DMARC record.
Create the /etc/rspamd/local.d/dkim_signing.conf configuration file.
The selector="default"; line is derived from the first part of the DKIM DNS record (default._domainkey....) created above.
Enable and start Rspamd.
Change the lines below in /etc/mail/smtpd.conf and restart OpenSMTPD to enable Rspamd.
Test the mail server with POP3 or IMAP email client. If you do not require webmail, stop here.
When prompted, please choose the most current version of PHP.
Fetch the RainLoop webmail tarball and extract it to /var/www/htdocs/.
Use the Standard Edition which includes an automatic updater.
Copy /etc/examples/acme-client.conf to /etc
Add the following lines at the bottom of the file:
Create a DNS entry (either CNAME or A record) for subdomain webmail.example.com
Edit /etc/httpd.conf following the example below.
Run the httpd syntax check.
Enable and start httpd.
Request the Let's Encrypt certificate.
Add the server definitions for RainLoop to /etc/httpd.conf
Configure PHP to allow attachments up to 25 megabytes. Make the following changes in /etc/php-7.3.ini:
Enable the necessary PHP modules by copying their configuration files to /etc/php-7.3/
Check the syntax of /etc/httpd.conf
Enable and start httpd and php-fpm.
Browse to https://webmail.example.com/?admin.
The default username is: admin
The default password is: 12345.
Browse to each of the configuration sections and make your desired changes. Once you have finished with the configuration, log into webmail at https://webmail.example.com
0 Comments
Be the first to comment and share your perspective with the community.