User Tools

Site Tools


wiki:mail_server_setup

Mail server setup

How to set up a mail server using the following software:

  • OS: CentOS 6.5
  • MTA: Postfix 2.6.6
  • IMAP server: Dovecot 2.0.9
  • IMAP client: Roundcube 1.0
  • Spam filter: SpamAssassin 3.3.1
  • Sieve filter: dovecot-pigeonhole 2.09
  • IMAP synchronization: imapsync 1.584
  • DKIM: opendkim 2.9.0

I don't pretend to be an “email expert”. This is the configuration of my own server, I gathered information from man pages, documentation, tutorials, etc. There may be some errors or optimizations to do, but everything is working. Setting up a mail server is not easy, and you will need to take your time to achieve your goal.

Postfix

Install postfix:

# yum install postfix

Set the following variables in /etc/postfix/main.cf according to your doamin:

myhostname = mail.example.org
mydomain = example.org
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Mailbox/

Start postfix:

# service postfix start

Dovecot

Install dovecot:

# yum install dovecot

Add imap to the list of protocols in /etc/dovecot/dovecot.conf:

protocols = imap

Make sure the imap protocol is uncommented in /etc/dovecot/20-imap.conf:

protocol imap {
  # [...]
}

Now tell dovecot to use SSL/TLS in /etc/dovecot/conf.d/10-ssl.conf (you need a certificate, self-signed or not):

ssl = yes
 
ssl_cert = </etc/pki/dovecot/certs/example.org.pem
ssl_key = </etc/pki/dovecot/private/example.org.key

Configure SASL (in /etc/postfix/main.cf):

# Source: http://wiki.centos.org/HowTos/postfix_sasl
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
 
smtpd_recipient_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination
 
smtpd_use_tls = yes
smtpd_tls_auth_only = yes
tls_random_source = dev:/dev/urandom
smtpd_tls_cert_file = /etc/postfix/certs/example.org.pem
smtpd_tls_key_file = /etc/postfix/certs/example.org.key

Set the authentication mechanism in /etc/dovecot/10-auth.conf:

auth_mechanisms = plain login

Set the mail directory location in /etc/dovecot/conf.d/10-mail.conf:

mail_location = maildir:~/Mailbox

Set user and group to postfix in /etc/dovecot/conf.d/10-master.conf:

service auth {
  # [...]
 
  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix
  }
}

Start dovecot:

# service start dovecot

Roundcube

TODO

SpamAssassin

TODO

Pigeonhole

TODO

Extra

imapsync

In my case, I wanted to copy the All Mail folder from Gmail into the Inbox folder on my server.

Install imapsync:

# yum install imapsync

Create a mailsync.sh script with the following content (change the expressions between * to match your configuration):

#!/bin/bash
imapsync \
--host1 imap.gmail.com --user1 *username*@gmail.com \
--passfile1 gmail.passfile1 \
--host2 localhost --user2 *localusername* \
--passfile2 myserver.passfile2 \
--ssl1 \
--useheader 'Message-Id' --skipsize --allowsizemismatch \
--syncinternaldates --noauthmd5 -nofoldersizes \
--split1 100 --split2 100 \
--regextrans2 's/\[Gmail\]\.All\ Mail/Inbox/' \
--include "All\ Mail" --delete2 \
--maxsize 10000000

Make the script executable and execute it:

$ chmod +x mailsync.sh
$ ./mailsync.sh

OpenDKIM

wiki/mail_server_setup.txt · Last modified: 2014/05/14 13:19 by bparmentier