Simple mail server with webmail

From Gentoo Wiki
Jump to: navigation, search

This guide is for getting basic mail server working in small amount of time. You can always add more features later. This guide uses postfix MTA, dovecot IMAP, POP, SASL and SquirrelMail webmail.

Postfix MTA

Install mail-mta/postfix. Enable dovecot-sasl, ipv6, pam and ssl USE flags. See also the Postfix article.

root #emerge --ask postfix

If this is a new install, the previous command should uninstall mail-mta/ssmtp. If it fails to uninstall mail-mta/ssmtp, you need to manually uninstall it, because it blocks Postfix:

root #emerge --ask -C ssmtp

Configure Postfix.

FILE /etc/postfix/
# basic config
myhostname =
mydomain =
myorigin =
inet_interfaces = all
mynetworks_style = host
mydestination = $myhostname, localhost, $mydomain, mail.$mydomain, www.$mydomain
home_mailbox = .maildir/

# sasl config
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

Edit aliases to redirect root mails to webmaster:

FILE /etc/mail/aliases
root: webmaster

Generate aliases database:

root #newaliases

Redirect root mails to webmaster:

FILE /root/.forward

Check for errors:

root #postfix check

Start Postfix:

root #/etc/init.d/postfix start

Check /var/log/mail.log for errors:

root #cat /var/log/mail.log

dovecot IMAP, POP & SASL

Install net-mail/dovecot. Enable USE flags : bzip2 ipv6 maildir pam ssl zlib

root #emerge --ask dovecot

Configure dovecot:

FILE /etc/dovecot/dovecot.conf
protocols = imap pop3

# sasl config
service auth {
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix
    group = postfix

Start dovecot:

root #/etc/init.d/dovecot start

SquirrelMail webmail

The information in this section is probably outdated. You can help the Gentoo Wiki by verifying and updating this article.

Change dir to webserver root:

user $cd /home/webmaster/htdocs

Unpack squirrelmail:

user $tar xjf squirrelmail-webmail-1.4.22.tar.bz2

Configure squirrelmail:

user $cd squirrelmail-webmail-1.4.22/config
user $cp config_default.php config.php
FILE config.php
$data_dir = '/home/webmaster/.squirrelmail/data/';
$attachment_dir = '/home/webmaster/.squirrelmail/attach/';
$domain = '';

Create data dirs and set permissions:

user $mkdir -p /home/webmaster/.squirrelmail/data/
user $mkdir -p /home/webmaster/.squirrelmail/attach/
root #chown -R webmaster:lighttpd /home/webmaster/.squirrelmail/
user $chmod -R 770 /home/webmaster/.squirrelmail/

Debug squirrelmail by opening url:

You can access webmail by opening url:

Everything should be working now.


Check your error log (mine is /var/log/messages).

If you get this error and can't login to squirrelmail: "auth: Fatal: sql: driver not set in configuration file /etc/dovecot/dovecot-sql.conf.ext"

then try these changes and restart dovecot:

FILE /etc/dovecot/conf.d/10-auth.conf
# Ensure that this line is commented out:
#!include auth-sql.conf.ext