#Installing configuring Postfix/Dovecot/Spamassassin/Roundcube
I've documented the steps in short to help me reproduce all the steps. Published it here for improvement and as a reference for others. Of course feel free to comment to improve this document.
This Gist is quite big and not all details are fully explained. But if you're going to run a mailserver you should be able to fill in the missing parts. The most important are covered. But be sure to read up to understand the meaning of all the stuff you configure. Since I used a lot of references of other sources (See at the end) I left out a lot of explanation in this document.
Don't forget that I'm not a Postfix/Dovecot/Spamassasin pro either. I just got it working the way I wanted to.
- Used Ubuntu 12.04 LTS.
- Set a root password.
- Set the hostname and updated the /etc/hosts file.
- Updated and upgraded the operating system and all installed packages.
- Created a Linux user with sudo access.
- Optional: Created SSH keys for secure SSH sessions.
- Made sure that your firewall is not blocking any of the standard mail ports (25, 465, 587, 110, 995, 143, and 993).
- Sync the time using: sudo ntpdate pool.ntp.org
Let's start:
apt-get install postfix postfix-mysql dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql mysql-server
When prompted, type a new secure password for the root MySQL user, remember them. You'll be prompted to select a Postfix configuration. Select Internet Site, as shown below.
You'll be prompted to enter a System mail name. You can use your FQDN or any domain name that resolves to the server. This will become your server's default domain for mail when none is specified. Like mail.mydomain.nl
You just installed packages to support three applications: MySQL, Postfix, and Dovecot. Now it's time to configure the individual applications to work together as a mail server.
#MySQL First, you'll create a dedicated database in MySQL for your mail server. It will have three tables: one with domains, one with email addresses and encrypted passwords, and one with email aliases. You'll also create a dedicated MySQL user for Postfix and Dovecot.
mysqladmin -p create mailserver
Enter the MySQL root password. Log in to MySQL by entering the following command:
mysql -p mailserver
GRANT SELECT ON mailserver.* TO 'mailuser'@'127.0.0.1' IDENTIFIED BY 'another nice password to remember’;
FLUSH PRIVILEGES;
CREATE TABLE `virtual_domains` ( `id` int(11) NOT NULL auto_increment, `name` varchar(50) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `virtual_users` ( `id` int(11) NOT NULL auto_increment, `domain_id` int(11) NOT NULL, `password` varchar(106) NOT NULL, `email` varchar(100) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`), FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `virtual_aliases` ( `id` int(11) NOT NULL auto_increment, `domain_id` int(11) NOT NULL, `source` varchar(100) NOT NULL, `destination` varchar(100) NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8;
You've created the database and necessary tables in MySQL.
#Adding Data
Now that you've created the database and tables, let's add some data to MySQL. Here's how:
Add your domains to the virtual_domains table. You can add as many domains as you want in the VALUES section of the command below, but in this example you'll add just the primary domain (example.com), your hostname (hostname), your FQDN (hostname.example.com), and localhost.example.com. (You'll add localhost in a different file later). Be sure to replace example.com and hostname with your own domain name and hostname. You'll need an id value and a name value for each entry. Separate each entry with a comma (,), and close the last one with a semicolon (;).
INSERT INTO `mailserver`.`virtual_domains` (`id` ,`name`)VALUES ('1', 'example.com'), ('2', 'hostname.example.com'), ('3', 'hostname'), ('4', 'localhost.example.com');
Make a note of which id goes with which domain - you'll need for the next two steps.
INSERT INTO `mailserver`.`virtual_users` (`id`, `domain_id`, `password` , `email`)VALUES ('1', '1', ENCRYPT('firstpassword', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))), '[email protected]'), ('2', '1', ENCRYPT('secondpassword', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))), '[email protected]');
For creating aliases, you can do the folowing.
INSERT INTO `mailserver`.`virtual_aliases` (`id`, `domain_id`, `source`, `destination`)VALUES ('1', '1', '[email protected]', '[email protected]');
Check if it's all there:
SELECT * FROM mailserver.virtual_domains;
SELECT * FROM mailserver.virtual_users;
SELECT * FROM mailserver.virtual_aliases;
exit
cp /etc/postfix/main.cf /etc/postfix/main.cf.orig
nano /etc/postfix/main.cf
The myhostname and mydestination lines are specific to your server, but everything else should be fine for now.
Comment out all of the lines in the #TLS parameters section, and then paste in the four new lines shown below. Since we're using Dovecot for authentication, we're going to use Dovecot's default certificate rather than Postfix's default certificate. For increased security, we're also going to force users to use TLS encryption.
# TLS parameters
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
#smtpd_use_tls=yes
#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_cert_file=/etc/ssl/certs/dovecot.pem
smtpd_tls_key_file=/etc/ssl/private/dovecot.pem
smtpd_use_tls=yes
smtpd_tls_auth_only = yes
Add the following below these TLS settings;
#Enabling SMTP for authenticated users, and handing off authentication to Dovecot
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_unauth_destination
Change the mydestination line so that it reads localhost only;
mydestination = localhost
Add a new line for local mail delivery
#Handing off local delivery to Dovecot's LMTP, and telling it where to store mail
virtual_transport = lmtp:unix:private/dovecot-lmtp
Add the following values to configure your virtual domains, users, and aliases;
#Virtual domains, users, and aliases
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
Now create those three files referenced above to make Postfix look for the data in the MySql tables.
nano /etc/postfix/mysql-virtual-mailbox-domains.cf
Content
user = mailuser
password = mailuserpass
hosts = 127.0.0.1
dbname = mailserver
query = SELECT 1 FROM virtual_domains WHERE name='%s'
Then restart postfix
service postfix restart
Run the following command to let Postfix find your first domain. Be sure to replace example.com with your first virtual domain. The command should return 1 if it is successful; if nothing is returned, you have an issue.
postmap -q example.com mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
Create the 2nd file
nano /etc/postfix/mysql-virtual-mailbox-maps.cf
Content
user = mailuser
password = mailuserpass
hosts = 127.0.0.1
dbname = mailserver
query = SELECT 1 FROM virtual_users WHERE email='%s'
Restart postfix
service postfix restart
Test Postfix to verify that it can find the first email address in your MySQL table. Enter the following command, replacing [email protected] with the first email address in your MySQL table. You should again receive 1 as the output:
postmap -q [email protected] mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
Create the 3rd file:
nano /etc/postfix/mysql-virtual-alias-maps.cf
Content
user = mailuser
password = mailuserpass
hosts = 127.0.0.1
dbname = mailserver
query = SELECT destination FROM virtual_aliases WHERE source='%s'
Then restart postfix again
service postfix restart
Test Postfix to verify that it can find your aliases by entering the following command. Be sure to replace [email protected] with the actual alias you entered:
postmap -q [email protected] mysql:/etc/postfix/mysql-virtual-alias-maps.cf
Make a copy of the original master.cf file
cp /etc/postfix/master.cf /etc/postfix/master.cf.orig
nano /etc/postfix/master.cf
Locate and uncomment the two lines starting with submission and smtps.
submission inet n - - - - smtpd
smtps inet n - - - - smtpd
Save your changes and restart postfix.
service postfix restart
#Dovecot
Copy all of the configuration files so that you can easily revert back to them if needed. Enter the following commands, one by one:
cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.orig
cp /etc/dovecot/conf.d/10-mail.conf /etc/dovecot/conf.d/10-mail.conf.orig
cp /etc/dovecot/conf.d/10-auth.conf /etc/dovecot/conf.d/10-auth.conf.orig
cp /etc/dovecot/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext.orig
cp /etc/dovecot/conf.d/10-master.conf /etc/dovecot/conf.d/10-master.conf.orig
cp /etc/dovecot/conf.d/10-ssl.conf /etc/dovecot/conf.d/10-ssl.conf.orig
nano /etc/dovecot/dovecot.conf
Verify that dovecot.conf is including all of the other configuration files. This option should be enabled by default:
!include conf.d/*.conf
Make sure that lmtp is added to the protocols, like:
# Enable installed protocols
!include_try /usr/share/dovecot/protocols.d/*.protocol
protocols = imap pop3 lmtp
Edit and check:
nano /etc/dovecot/conf.d/10-mail.conf
The only 2 values I have uncommented and changed are:
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_privileged_group = mail
Save the file and now check the permissions for /var/mail using the following command:
ls -ld /var/mail
Verify that the permissions for /var/mail are as follows:
drwxrwsr-x 2 root mail 4096 Mar 6 15:08 /var/mail
Create the /var/mail/vhosts/ folder and the folder(s) for each of your domains by entering the following command:
mkdir -p /var/mail/vhosts/example.com
Create the vmail user with a user and group id of 5000 by entering the following commands, one by one. This user will be in charge of reading mail from the server.
groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /var/mail
Change the owner of the /var/vmail/ folder and its contents to belong to vmail by entering the following command:
chown -R vmail:vmail /var/mail
Open the user authentication file for editing by entering the command below. You need to set up authentication so only authenticated users can read mail on the server. You also need to configure an authentication socket for outgoing mail, since we told Postfix that Dovecot was going to handle that. There are a few different files related to authentication that get included in each other.
nano /etc/dovecot/conf.d/10-auth.conf
Disable plain-text authentication by uncommenting this line:
disable_plaintext_auth = yes
Set the auth_mechanisms by modifying the following line:
auth_mechanisms = plain login
Add a hash tag (#) to comment out the system user login line:
#!include auth-system.conf.ext
Enable MySQL authentication by uncommenting the auth-sql.conf.ext line. That section should look like this:
#!include auth-system.conf.ext
!include auth-sql.conf.ext#
!include auth-ldap.conf.ext#
!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext
Save your changes to the /etc/dovecot/conf.d/10-auth.conf file.
Now you need to create the /etc/dovecot/conf.d/auth-sql.conf.ext file with your authentication information.
nano /etc/dovecot/conf.d/auth-sql.conf.ext
passdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/var/mail/vhosts/%d/%n
}
Now edit dovecot-sql.conf.ext
nano /etc/dovecot/dovecot-sql.conf.ext
Uncomment and set the drive line like this:
driver = mysql
Uncomment the connect line and set your MySQL connection information. Make sure you use your own password and any other custom settings:
connect = host=127.0.0.1 dbname=mailserver user=mailuser password=mailuserpass
Uncomment the default_pass_scheme line and set it to SHA512-CRYPT. This tells Dovecot to expect the passwords in an ecrypted format (which is how they are stored in the database).
default_pass_scheme = SHA512-CRYPT
Uncomment the password_query line and set it to the following. This is a MySQL query that Dovecot uses to retrieve the password from the database.
password_query = SELECT email as user, password FROM virtual_users WHERE email='%u';
This password query lets you use an email address listed in the virtual_users table as your username credential for an email account. The primary email address should still be used as the username, even if you have set up your email client for an alias.
Save your changes to the /etc/dovecot/dovecot-sql.conf.ext file.
Change the owner and group of the /etc/dovecot/ directory to vmail and dovecot by entering the following command:
chown -R vmail:dovecot /etc/dovecot
Change the permissions on the /etc/dovecot/ directory by entering the following command:
chmod -R o-rwx /etc/dovecot
Open the sockets configuration file by entering the following command. You'll change the settings in this file to set up the LMTP socket for local mail delivery, and the auth socket for authentication. Postfix uses these sockets to connect to Dovecot's services.
nano /etc/dovecot/conf.d/10-master.conf
Disable unencrypted IMAP and POP3 by setting the protocols' ports to 0, as shown below. This will force your users to use secure IMAP or secure POP on 993 or 995 when they configure their mail clients:
service imap-login {
inet_listener imap {
port = 0
}...
}
service pop3-login {
inet_listener pop3 {
port = 0
}...
}
Make sure you leave the secure versions alone - imaps and pop3s - so their ports still work. The default settings for imaps and pop3s are fine. You can leave the port lines commented out, as the default ports are the standard 993 and 995.
Find the service lmtp section and use the configuration shown below. You'll need to add a few lines in the unix_listener block. This section makes the socket for LMTP in the place we told Postfix to look for it.
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
# Create inet listener only if you can't use the above UNIX socket
#inet_listener lmtp {
# Avoid making LMTP visible for the entire internet
#address =
#port =
#}
}
Locate the service auth section and use the configuration shown below. You'll need to create a new unix_listener block, modify the existing one, and then uncomment and set the user. This section makes the authorization socket where we told Postfix to look for it:
service auth {
# auth_socket_path points to this userdb socket by default. It's typically
# used by dovecot-lda, doveadm, possibly imap process, etc. Its default
# permissions make it readable only by root, but you may need to relax these
# permissions. Users that have access to this socket are able to get a list
# of all usernames and get results of everyone's userdb lookups.
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
unix_listener auth-userdb {
mode = 0600
user = vmail
#group =
}
# Postfix smtp-auth
#unix_listener /var/spool/postfix/private/auth {
# mode = 0666
#}
# Auth process is run as this user.
user = dovecot
}
In the service auth-worker section, uncomment the user line and set it to vmail, as shown below.
service auth-worker {
# Auth worker process is run as root by default, so that it can access
# /etc/shadow. If this isn't necessary, the user should be changed to
# $default_internal_user.
user = vmail
}
Save your changes to the /etc/dovecot/conf.d/10-master.conf file.
Verify that the default Dovecot SSL certificate and key exist by entering the following commands, one by one:
ls /etc/ssl/certs/dovecot.pemls /etc/ssl/private/dovecot.pem
If you are using a different SSL certificate, you should upload the certificate to the server and make a note of its location and the key's location.
Open the SSL configuration file for editing by entering the following command. This is where we tell Dovecot where to find our SSL certificate and key, and any other SSL-related parameters.
nano /etc/dovecot/conf.d/10-ssl.conf
Verify that the ssl_cert setting has the path to your certificate, and that the ssl_key setting has the path to your key. The default setting here uses Dovecot's built-in certificate, so you can leave this as-is if you are using the Dovecot certificate. You should update the paths if you are using a different certificate and key.
ssl_cert = </etc/ssl/certs/dovecot.pem
ssl_key = </etc/ssl/private/dovecot.pem
Force your clients to use SSL encryption for all connections. Set ssl to required:
ssl = required
Save your changes to the /etc/dovecot/conf.d/10-ssl.conf file. Dovecot has been configured!
Restart Dovecot by entering the following command:
service dovecot restart
Set up a test account in an email client to make sure everything is working. You'll need to use the following parameters:
- Your full email address, including the @example.com part, is your username.
- Your password should be the one you added to the MySQL table for this email address.
- The incoming and outgoing server names must be a domain that resolves to your Linode.
- Both the incoming and outgoing servers require authentication and SSL encryption.
- You should use Port 993 for secure IMAP, Port 995 for secure POP3, and Port 25 with SSL for SMTP.
Try sending an email to this account from an outside email account and then reply to it. If it works, you're in business! You can check your mail log file in /var/log/mail.log
Congratulations! You now have a functioning mail server that can securely send and receive email. If things are not working smoothly, you may also want to consult the Troubleshooting Problems with Postfix, Dovecot, and MySQL guide. At this point, you may want to consider adding spam and virus filtering and a webmail client. If you haven't switched the DNS records for your mail server yet, you should be able to do so now. Once the DNS records have propagated, you will start receiving email for your domain on the server.
#Adding New Domains, Email Addresses, and Aliases
Now your mail server is up and running, but eventually you'll probably need to add new domains, email addresses, and aliases for your users. To do this, all you'll have to do is add a new line to the appropriate MySQL table. These instructions are for command-line MySQL, but you can just as easily use phpMyAdmin to add new entries to your tables as well.
##Domains
Here's how to add a new domain to your Postfix and Dovecot setup:
Open a terminal window and log in to your Linode via SSH.
Log in to your MySQL server with an appropriately privileged user. In this example, we'll use the root user:
mysql -u root -p mailserver
You should always view the contents of the table before adding new entries. Enter the following command to view the current contents of any table, replacing virtual_domains with your table:
SELECT * FROM mailserver.virtual_domains;
To add another domain, enter the following command, replacing newdomain.com with your domain name:
INSERT INTO `mailserver`.`virtual_domains` (`name`)VALUES ('newdomain.com');
Verify that the new domain has been added by entering the following command. You should see the new domain name in the output.
SELECT * FROM mailserver.virtual_domains;
Exit MySql
quit
##Email Addresses
Here's how to add a new email address to your Postfix and Dovecot setup:
INSERT INTO `mailserver`.`virtual_users` (`domain_id`, `password` , `email`)VALUES ('5', ENCRYPT('newpassword', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16))) , '[email protected]');
Be sure to use the correct number for the domain_id. In this case, we are using 5, because we want to make an email address for newdomain.com, and newdomain.com has an id of 5 in the virtual_domains table.
SELECT * FROM mailserver.virtual_users;
quit
Congratulations! You have successfully added the new email address to your Postfix and Dovecot setup.
##Aliases
Here's how to add a new alias to your Postfix and Dovecot setup:
The [email protected] needs to be an email address that already exists on your server.
INSERT INTO `mailserver`.`virtual_aliases` (`domain_id`, `source`, `destination`)VALUES ('5', '[email protected]', '[email protected]');
You will need to use the correct number for the domain_id. You should use the id of the domain for this email address; see the explanation in the email users section above.
Verify that the new alias has been added by entering the following command. You should see the new alias in the output.
SELECT * FROM mailserver.virtual_aliases;
quit
Congratulations! You have successfully added the new alias to your Postfix and Dovecot setup.
#Install Spamassassin
apt-get install spamassassin spamc
Then add a group for spamassassin
groupadd spamd
Then add the user spamd with the home directory /var/log/spamassassin:
useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd
mkdir /var/log/spamassassin
chown spamd:spamd /var/log/spamassassin
Setup spamassassin
nano /etc/default/spamassassin
Example config I'm using
##############################
# /etc/default/spamassassin
# Duncan Findlay
# WARNING: please read README.spamd before using.
# There may be security risks.
# Change to one to enable spamd
ENABLED=1
# Options
# See man spamd for possible options. The -d option is automatically added.
# SpamAssassin uses a preforking model, so be careful! You need to
# make sure --max-children is not set to anything higher than 5,
# unless you know what you're doing.
SAHOME="/var/log/spamassassin/"
#OPTIONS="--create-prefs --max-children 5 --helper-home-dir"
OPTIONS="--create-prefs --max-children 2 --username spamd -H ${SAHOME} -s ${SAHOME}spamd.log"
# Pid file
# Where should spamd write its PID to file? If you use the -u or
# --username option above, this needs to be writable by that user.
# Otherwise, the init script will not be able to shut spamd down.
PIDFILE="/var/run/spamd.pid”
# Set nice level of spamd
#NICE="--nicelevel 15"
# Cronjob
# Set to anything but 0 to enable the cron job to automatically update
# spamassassin's rules on a nightly basis
CRON=1
##############################
Then start spamassassin with:
service spamassassin start
Then do configure postfix for use with spamassassin so that postfix will pipe mail through spamassassin
nano /etc/postfix/master.cf
find the line:
smtp inet n - - - - smtpd
and add the following at the end!
-o content_filter=spamassassin
See below snippet of result:
# service type private unpriv chroot wakeup maxproc command + args
# (yes) (yes) (yes) (never) (100)
# ==========================================================================
smtp inet n - - - - smtpd -o content_filter=spamassassin
#smtp inet n - - - 1 postscreen
Now, Postfix will pipe the mail through Spamassassin. To setup after-queue content filter add the following line to the end of the file
spamassassin unix - n n - - pipe
user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
restart postfix using:
service postfix restart
To get the maximum use of Spamassassin you have to create rules. Open the Spamassassin default rules file using:
nano /etc/spamassassin/local.cf
uncomment the line:
rewrite_header Subject [***** SPAM _SCORE_ *****]
required_score 5.0
To use bayes theorem to check mails, uncomment or add the line:
use_bayes 1
To enable bayes auto learning, uncomment or add the line:
bayes_auto_learn 1
After adding the above details, save the file and restart spamassassin.
service spamassassin restart
#PhpMyAdmin
Install apache2/php5/phpMyAdmin for easier management for domains/mailboxes/aliasses
Make sure that only the default-ssl site is active Then
nano /var/www/.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*) https://mail.mydomain.nl/$1 [L]
Edit
sudo nano /etc/phpmyadmin/apache.conf
Make sure the last line in the block below (AllowOverride All) is added...
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Then make sure that you use http auth for accessing phpmyadmin:
sudo nano /usr/share/phpmyadmin/.htaccess
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /var/.htpasswd
Require valid-user
sudo htpasswd -c /var/.htpasswd admin
sudo service apache2 restart
#Install Roundcube
Log into mysql
mysql -u root -p
Create the roundcube database
create database roundcubedb;
Create the roundcube db user
create user usercube;
set password for 'usercube' = password('another nice password to remember');
grant all privileges on roundcubedb.* to 'usercube'@'localhost' identified by 'another password to remember'
exit
Download roundcoube (checksum.org is one of my domains)
wget http://checksum.org/roundcubemail-0.9.5.tar.gz
tar -xzvf roundcubemail-0.7.1.tar.gz -C /var/www
gunzip roundcubemail-0.9.5.tar.gz
tar -xvf roundcubemail-0.7.1.tar
mv /var/www/roundcubemail-0.9.5 /var/www/webmail
sudo chown -R www-data.www-data /var/www/webmail/temp
sudo chown -R www-data.www-data /var/www/webmail/logs
mysql -u root -p roundcubedb < /var/www/webmail/SQL/mysql.initial.sql
Go To: https://mail.mydomain.nl/webmail/installer/
And follow the instructions.
If you want users to be able to change their password within Roundcube use the password plugin by editing:
nano roundcubemail/config/main.inc.php
Change the following line to activate the plugin:
$rcmail_config['plugins'] = array('password');
nano roundcubemail/plugins/password/config.inc.php
The config options below are used for roundcube to determine which field in the database to set for the password.
$rcmail_config['password_db_dsn'] = 'mysql://mailuser:usethecorrectpassword@localhost/mailserver';
$rcmail_config['password_query'] = 'UPDATE virtual_users SET password=%c WHERE email=%u’;
$rcmail_config['password_crypt_hash'] = 'md5’;
I've created a free SSL certificate at http://www.startssl.com for my mail domain.
That is something you should be able to do for yourself. Creating the CRS goes as follows:
openssl req -new -newkey rsa:2048 -nodes -keyout yourdomain.key -out yourdomain.csr
##Moving spam to the Junk folder automatically
apt-get install dovecot-sieve dovecot-managesieved
nano /etc/dovecot/conf.d/20-lmtp.conf
Add following:
protocol lmtp {
postmaster_address = [email protected]
mail_plugins = $mail_plugins sieve
}
nano /etc/dovecot/conf.d/90-sieve.conf
add following
plugin {
sieve = ~/.dovecot.sieve
sieve_global_path = /var/lib/dovecot/sieve/default.sieve
sieve_dir = ~/sieve
sieve_global_dir = /var/lib/dovecot/sieve/
}
Restart Dovecot.
service dovecot restart
mkdir /var/lib/dovecot/sieve/
chown -R vmail:vmail /var/lib/dovecot
nano /var/lib/dovecot/sieve/default.sieve
put in the following:
require "fileinto";
if header :contains "X-Spam-Flag" "YES" {
fileinto "Junk";
}
Compile the script:
sievec /var/lib/dovecot/sieve/default.sieve
apt-get install opendkim opendkim-tools
mkdir /etc/opendkim
cd /etc/opendkim
Generate the (1024 bit) key (for each domain you send mail for)
mkdir -p /etc/opendkim/keys/domain.tld
cd /etc/opendkim/keys/domain.tld
opendkim-genkey -r -d domain.tld
chown opendkim:opendkim default.private
Add the keys to a keytable
nano /etc/opendkim/KeyTable
And reference the key files for the domains like this
default._domainkey.domain.tld domain.tld:default:/etc/opendkim/keys/domain.tld/default.private
default._domainkey.domain2.tld domain2.tld:default:/etc/opendkim/keys/domain2.tld/default.private
Add domains to SigningTable
nano /etc/opendkim/SigningTable
domain.tld default._domainkey.domain.tld
domain2.tld default._domainkey.domain2.tld
List the trusted hosts in a seperate file
nano /etc/opendkim/TrustedHostList.txt
Like this
#
# External Hosts that OpenDKIM will Trust
127.0.0.1
localhost
domain1.com
domain2.com
domain3.com
yourdomain.nl
mail.yourdomain.nl
Add to DKIM public key to DNS
For domain.tld
cat /etc/opendkim/keys/domain.tld/default.txt
For domain2.tld
cat /etc/opendkim/keys/domain2.tld/default.txt
See the content of opendkim.conf below:
nano /etc/opendkim.conf
Then configure Postfix to use DKIM
nano /etc/postfix/main.cf
And add the following
# Add the DKIM milter
milter_default_action = accept
milter_protocol = 2
smtpd_milters = inet:localhost:8891
non_smtpd_milters = inet:localhost:8891
To update the spamassasin rules twice a day edit:
nano /etc/root/cron.d/spamassassin
- */12 * * * sa-update && service spamassassin restart >/dev/null 2>&1 | mail -s "cron output" [email protected]
I've used the following sources to combine all the stuff above:
- https://library.linode.com/email/postfix/postfix2.9.6-dovecot2.0.19-mysql#sph_aliases
- https://rtcamp.com/tutorials/mail/server/sieve-filtering/
- https://google.com
About the server time, since it's sending out emails, you might want to check:
https://www.digitalocean.com/community/articles/how-to-set-up-time-synchronization-on-ubuntu-12-04
And/or run to set the timezone of the server:
sudo dpkg-reconfigure tzdata
#tips
- Be sure to setup an abuse email address for the mailserver. ([email protected])
- Be sure to setup reverse DNS for your email server. (test it with "host ip_address_of_your_mailserver)
- Check spammyness of your email, SPF and DKIM and other settings at http://www.mail-tester.com/
- Create/generate an SPV record at http://www.spfwizard.net/
Awesome writeup