Mailcow
Have the official guide in hand.
Install
su
umask
cd /opt
git clone https://github.com/mailcow/mailcow-dockerized
cd mailcow-dockerized
./generate_config.sh
Configure
Set mailserver hostname (FQDN) to mail.privatenode.xyz.
Edit mailcow.conf:
MAILCOW_HOSTNAME=mail.privatenode.xyz
MAILCOW_PASS_SCHEME=BLF-CRYPT
DBNAME=<unique database>
DBUSER=<unique username>
DBPASS=<long alphanumeric string>
DBROOT=<long alphanumeric string>
SKIP_CLAMD=n (change to Y if performance is poor)
SKIP_SOGO=n (change to Y to disable SOGo, webmail, DAV & ActiveSync)
SKIP_SOLR=y (indexing uses memory and stores readable copies of mail)
# if using behind reverse proxy:
HTTP_BIND=127.0.0.1
HTTP_PORT=8080
HTTPS_BIND=127.0.0.1
HTTPS_PORT=8443
# Fixed project name, lower case only
COMPOSE_PROJECT_NAME=privacyroot
Use this config if not using a reverse proxy:
server {
root /web;
listen 80 default_server;
listen [::]:80 default_server;
include /etc/nginx/conf.d/server_name.active;
if ( $request_uri ~* "%0A|%0D" ) { return 403; }
location ^~ /.well-known/acme-challenge/ {
allow all;
default_type "text/plain";
}
location / {
return 301 https://$host$uri$is_args$args;
}
}
DNS
Initial DNS configuration:
@ A 173.212.237.88
mail A 173.212.237.88
autodiscover CNAME mail.privatenode.xyz
autoconfig CNAME mail.privatenode.xyz
imap CNAME mail.privatenode.xyz
pop3 CNAME mail.privatenode.xyz
smtp CNAME mail.privatenode.xyz
@ MX 10 mail.privatenode.xyz
@ TXT v=spf1 mx -all
dkim._domainkey @ TXT v=DKIM1; k=rsa; t=s; s=email; p=<DKIM key>
_25._tcp.mail @ TLSA 3 1 1 <TLSA key>
_dmarc TXT "v=DMARC1; p=reject; rua=mailauth@privatenode.xyz"
_caldavs._tcp TXT "path=/SOGo/dav/"
_carddavs._tcp TXT "path=/SOGo/dav"
_autodiscover._tcp SRV 0 1 443 mail.privatenode.xyz
_caldavs._tcp SRV 0 1 443 mail.privatenode.xyz
_carddavs._tcp SRV 0 1 443 mail.privatenode.xyz
_imaps._tcp 0 1 993 mail.privatenode.xyz
_imap._tcp 0 1 143 mail.privatenode.xyz
_pop3s._tcp 0 1 110 mail.privatenode.xyz
_sieve._tcp 0 1 4190 mail.privatenode.xyz
_smtps_.tcp 0 1 464 mail.privatenode.xyz
_submission._tcp 0 1 587 mail.privatenode.xyz
DMARC
Make sure a valid DMARC entry is in the DNS:
_dmarc TXT "v=DMARC1; p=reject; rua=mailauth@privatenode.xyz"
DKIM
Generate a DKIM key in the Mailcow web UI, and be sure to add it to the DNS records. It's a TXT record called dkim._domainkey and it'll look something like (omit all spaces):
v=DKIM1;k=rsa;t=s;s=email;p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA+QHULp3CCzYSiXEneccTam7IHq5KEOnjv86/zKFSJ+jT3FBdKDwH7iZE7xCcFgiYtzj3tKmsCzb80CmJg00g5duMLpLBsxx3hKcGdLjjz1SNvi77+75Bnzl9+YCa3zM4srLo7Dud9lHUXilUc9/AqOd/TBmT+2IuWtUUan7SuP0mabhUJfwQuIV1d3aujJ5HDSeeAuYYy4jQSXvkK/sd/xU1mXKbYHR09RnSpEjhU54t+TubP2Q5SRIoicbQBbjegabnDoqdeGDpXhV550t9Swvg9vglUaEjNKY8KXKkepqOhh+9uePnLMk4a132DlzeXWOm1jxWi6OxTvfS+gIGqwIDAQAB
DANE/TLSA
Add another DNS record, this time TLSA called _25._tcp.mail and value will look something like 1c62dd636ef612cf93b40796f19c20e6935ed85dd81a82c9d3b8059fe4bc1aee. The value must be a hash matching the TLS cert.
Roundcube
wget the latest Roundcube.
Still as root user:
cd /opt/mailcow-dockerized/data/web
wget -O - https://github.com/roundcube/roundcubemail/releases/download/1.5.2/roundcubemail-1.5.2-complete.tar.gz | tar xfvz -
mv roundcubemail-1.5.2 rc
chown -R root: rc/
# Fix Allow remote resources, should not be required in 1.6:
sed -i "s/\$prefix = '\.\/';/\$prefix = preg_replace\('\/\[\?\&]\.\*\$\/', '', \$_SERVER\['REQUEST_URI'] \?\? ''\) \?: '\.\/';/g" rc/program/include/rcmail.php
Create /opt/mailcow-dockerized/data/web/rc/config/config.inc.php and use randomly generated alphanumeric string for des_key:
<?php
error_reporting(0);
if (!file_exists('/tmp/mime.types')) {
file_put_contents("/tmp/mime.types", fopen("http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types", 'r')>
}
$config = array();
$config['db_dsnw'] = 'mysql://' . getenv('DBUSER') . ':' . getenv('DBPASS') . '@mysql/' . getenv('DBNAME');
$config['default_host'] = 'tls://dovecot';
$config['default_port'] = '143';
$config['smtp_server'] = 'tls://postfix';
$config['smtp_port'] = 587;
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['support_url'] = '';
$config['product_name'] = 'Roundcube Webmail';
$config['des_key'] = '2c7o6mURDVCwkYh9TU9VX9hLSsQ7F466agJsSk7yyXgip9WK5ra98ohFN9JeScbR';
$config['log_dir'] = '/dev/null';
$config['temp_dir'] = '/tmp';
$config['plugins'] = array(
'archive',
'managesieve',
'password',
'carddav',
);
$config['enable_spellcheck'] = false;
$config['mime_types'] = '/tmp/mime.types';
$config['imap_conn_options'] = array(
'ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true)
);
$config['enable_installer'] = true;
$config['smtp_conn_options'] = array(
'ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true)
);
$config['db_prefix'] = 'mailcow_rc1';
Go to https://mail.privatenode.xyz/rc/installer, follow instructions, initialize database. Delete /opt/mailcow-dockerized/data/web/rc/installer afterwards.
To configure ManageSieve, open /opt/mailcow-dockerized/data/web/rc/plugins/managesieve/config.inc.php:
<?php
// managesieve server port. When empty the port will be determined automatically
// using getservbyname() function, with 4190 as a fallback.
$config['managesieve_port'] = 4190;
// managesieve server address, default is localhost.
// Replacement variables supported in host name:
// %h - user's IMAP hostname
// %n - http hostname ($_SERVER['SERVER_NAME'])
// %d - domain (http hostname without the first part)
// For example %n = mail.domain.tld, %d = domain.tld
$config['managesieve_host'] = 'tls://dovecot';
$config['managesieve_conn_options'] = array(
'ssl' => array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true)
);
// authentication method. Can be CRAM-MD5, DIGEST-MD5, PLAIN, LOGIN, EXTERNAL
// or none. Optional, defaults to best method supported by server.
// $config['managesieve_auth_type'] = null;
// Optional managesieve authentication identifier to be used as authorization proxy.
// Authenticate as a different user but act on behalf of the logged in user.
// Works with PLAIN and DIGEST-MD5 auth.
// $config['managesieve_auth_cid'] = null;
// Optional managesieve authentication password to be used for imap_auth_cid
// $config['managesieve_auth_pw'] = null;
// use or not TLS for managesieve server connection
// Note: tls:// prefix in managesieve_host is also supported
// $config['managesieve_usetls'] = false;
// Connection socket context options
// See http://php.net/manual/en/context.ssl.php
// The example below enables server certificate validation
//$config['managesieve_conn_options'] = [
// 'ssl' => [
// 'verify_peer' => true,
// 'verify_depth' => 3,
// 'cafile' => '/etc/openssl/certs/ca.crt',
// ],
// ];
// Note: These can be also specified as an array of options indexed by hostname
// $config['managesieve_conn_options'] = null;
// A file with default script content (e.g. spam filter)
$config['managesieve_default'] = '/etc/dovecot/sieve/global';
// The name of the script which will be used when there's no user script
$config['managesieve_script_name'] = 'managesieve';
// Sieve RFC says that we should use UTF-8 encoding for mailbox names,
// but some implementations work with UTF7-IMAP encoding only.
// Defaults to UTF7-IMAP
$config['managesieve_mbox_encoding'] = 'UTF-8';
// I need this because my dovecot (with listescape plugin) uses
// ':' delimiter, but creates folders with dot delimiter
$config['managesieve_replace_delimiter'] = '';
// disabled sieve extensions (body, copy, date, editheader, encoded-character,
// envelope, environment, ereject, fileinto, ihave, imap4flags, index,
// mailbox, mboxmetadata, regex, reject, relational, servermetadata,
// spamtest, spamtestplus, subaddress, vacation, variables, virustest, etc.
// Note: not all extensions are implemented
$config['managesieve_disabled_extensions'] = [];
// Enables debugging of conversation with sieve server. Logs it into <log_dir>/sieve
$config['managesieve_debug'] = false;
// Enables features described in http://wiki.kolab.org/KEP:14
$config['managesieve_kolab_master'] = false;
// Script name extension used for scripts including. Dovecot uses '.sieve',
// Cyrus uses '.siv'. Doesn't matter if you have managesieve_kolab_master disabled.
$config['managesieve_filename_extension'] = '.sieve';
// List of reserved script names (without extension).
// Scripts listed here will be not presented to the user.
$config['managesieve_filename_exceptions'] = [];
// List of domains limiting destination emails in redirect action
// If not empty, user will need to select domain from a list
$config['managesieve_domains'] = [];
// Default list of entries in header selector
$config['managesieve_default_headers'] = ['Subject', 'From', 'To'];
// Enables separate management interface for vacation responses (out-of-office)
// 0 - no separate section (default),
// 1 - add Vacation section,
// 2 - add Vacation section, but hide Filters section
$config['managesieve_vacation'] = 1;
// Enables separate management interface for setting forwards (redirect to and copy to)
// 0 - no separate section (default),
// 1 - add Forward section,
// 2 - add Forward section, but hide Filters section
$config['managesieve_forward'] = 0;
// Default vacation interval (in days).
// Note: If server supports vacation-seconds extension it is possible
// to define interval in seconds here (as a string), e.g. "3600s".
$config['managesieve_vacation_interval'] = 0;
// Some servers require vacation :addresses to be filled with all
// user addresses (aliases). This option enables automatic filling
// of these on initial vacation form creation.
$config['managesieve_vacation_addresses_init'] = false;
// Sometimes you want to always reply with mail email address
// This option enables automatic filling of :from field on initial vacation form creation.
$config['managesieve_vacation_from_init'] = false;
// Supported methods of notify extension. Default: 'mailto'
$config['managesieve_notify_methods'] = ['mailto'];
// Enables scripts RAW editor feature
$config['managesieve_raw_editor'] = true;
// Disabled actions. Prevents user from performing specific actions by disabling
// the UI elements:
// - list_sets,
// Note: disabling list_sets removes the Filter sets widget from the UI and means
// the set defined in managesieve_script_name will always be used (and activated)
// - enable_disable_set,
// - delete_set,
// - new_set,
// - download_set,
// - new_filter,
// - delete_filter,
// - redirect: This one will remove 'redirect' option from the filter actions selector
// Note: This will not remove it for redirect actions already existing in the script.
// Note: This has no impact on the Forwarding UI
$config['managesieve_disabled_actions'] = [];
// List of hosts that support managesieve.
// Activate managesieve for selected hosts only. If this is not set all hosts are allowed.
// Example: $config['managesieve_allowed_hosts'] = ['host1.mydomain.com', 'host2.mydomain.com'];
$config['managesieve_allowed_hosts'] = null;
To enable password reset in Roundcube, enable its password plugin in /opt/mailcow-dockerized/data/web/rc/config/config.inc.php:
$config['plugins'] = array(
'archive',
'password',
);
Open /opt/mailcow-dockerized/data/web/rc/plugins/password/password.php and search for case 'ssha' and add this above it:
case 'ssha256':
$salt = rcube_utils::random_bytes(8);
$crypted = base64_encode( hash('sha256', $password . $salt, TRUE ) . $salt );
$prefix = '{SSHA256}';
break;
Then change the following in /opt/mailcow-dockerized/data/web/rc/plugins/password/config.inc.php:
$config['password_driver'] = 'sql';
$config['password_algorithm'] = 'ssha256';
$config['password_algorithm_prefix'] = '{SSHA256}';
$config['password_query'] = "UPDATE mailbox SET password = %P WHERE username = %u";
CarDAV
Add latest release of RCMCarDAV to integrate CardDAV address books to Roundcube:
cd /opt/mailcow-dockerized/data/web/rc/plugins
wget -O - https://github.com/mstilkerich/rcmcarddav/releases/download/v4.3.0/carddav-v4.3.0.tar.gz | tar xfvz -
chown -R root: carddav/
cd carddav
cp config.inc.php.dist config.inc.php
nano config.inc.php
$prefs['SOGo'] = array(
'name' => 'SOGo',
'username' => '%u',
'password' => '%p',
'url' => 'https://mail.privatenode.xyz/SOGo/dav/%u/',
'carddav_name_only' => true,
'use_categories' => true,
'active' => true,
'readonly' => false,
'refresh_time' => '02:00:00',
'fixed' => array( 'active', 'name', 'username', 'password', 'refresh_time' ),
'hide' => false,
);
Edit /opt/mailcow-dockerized/data/web/rc/config/config.inc.php and add $config['address_book_type'] = ''; so RCMCardDAV Personal Address Book is the only one.
Enigma plugin
To enable Enigma plugin:
sudo -i
cd /opt/mailcow-dockerized
mkdir -p ./data/web/rc/keys \
&& echo "<ifModule mod_authz_core.c>
Require all denied
</ifModule>
<ifModule !mod_authz_core.c>
Deny from all
</ifModule>" > ./data/web/rc/keys/.htaccess
nano ./data/web/rc/plugins/enigma/config.inc.php
Change $config['enigma_pgp_homedir'] to /web/rc/keys
Make web directory writeable by Malicow's php-fpm and restrict to key directory:
chown -R 82:82 ./data/web \
&& chmod 0700 ./data/web/rc/keys
Open pools.conf:
nano ./data/conf/phpfpm/php-fpm.d/pools.conf
Remove proc_open, proc_close, and proc_get_status from the php_admin_value[disable_functions] in the [web-worker] section.
Restart php-fpm: docker-compose restart php-fpm-mailcow
Autodiscover
Edit mailcow.conf and change ADDITIONAL_SAN:
ADDITIONAL_SAN=privatenode.xyz,mail.,imap.,smtp.*
Set nginx server names in /etc/nginx/conf.d/mailcow.conf:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name privatenode.xyz mail.privatenode.xyz imap.privatenode.xyz smtp.privatenode.xyz autodiscover.* autoconfig.*;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name privatenode.xyz mail.privatenode.xyz imap.privatenode.xyz smtp.privatenode.xyz autodiscover.* autoconfig.*;
ssl_certificate /opt/mailcow-dockerized/data/assets/ssl/cert.pem;
ssl_certificate_key /opt/mailcow-dockerized/data/assets/ssl/key.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# See https://ssl-config.mozilla.org/#server=nginx for the latest ssl settings recommendations
# An example config is given below
ssl_protocols TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5:!SHA1:!kRSA;
ssl_prefer_server_ciphers off;
location /Microsoft-Server-ActiveSync {
proxy_pass http://127.0.0.1:8080/Microsoft-Server-ActiveSync;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 75;
proxy_send_timeout 3650;
proxy_read_timeout 3650;
proxy_buffers 64 512k; # Needed since the 2022-04 Update for SOGo
client_body_buffer_size 512k;
client_max_body_size 0;
}
location / {
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0;
# The following Proxy Buffers has to be set if you want to use SOGo after the 2022-04 (April 2022) Update
# Otherwise a Login will fail like this: https://github.com/mailcow/mailcow-dockerized/issues/4537
proxy_buffer_size 128k;
proxy_buffers 64 512k;
proxy_busy_buffers_size 512k;
}
}
Do touch data/assets/ssl/force_renew, and systemctl reload nginx && systemctl restart nginx and then docker-compose down && docker-compose up -d
Troubleshoot
To check PHP logs:
docker-compose logs --tail=200 php-fpm-mailcow
To check NGINX logs:
docker-compose logs --tail=200 nginx-mailcow