Deprecated: Assigning the return value of new by reference is deprecated in /home/content/27/11020327/html/wp-settings.php on line 267

Deprecated: Assigning the return value of new by reference is deprecated in /home/content/27/11020327/html/wp-settings.php on line 269

Deprecated: Assigning the return value of new by reference is deprecated in /home/content/27/11020327/html/wp-settings.php on line 270

Deprecated: Assigning the return value of new by reference is deprecated in /home/content/27/11020327/html/wp-settings.php on line 287
Mail server setup on Ubuntu Lucid | ProDevTips - Web Development Tutorials

Mail server setup on Ubuntu Lucid

Update: I keep having to redo this setup and get tripped up on what to install all the time so here is the complete install line: apt-get install postfix dovecot opendkim postfix-mysql dovecot-pop3d dovecot-imapd which already assumes you’ve got mysql server installed.

Update: I just had to redo everything from scratch on a new build, here is how to add the virtual user:

groupadd -g 1001 virtual
useradd -g virtual -u 1001 virtual -d /var/spool/vmail -m

Update: I just got SMTP to work on a non default port. I applied the change described here, in my case I changed the line in so it looks like this:

26 inet n - n - - smtpd

I also applied the changes described by tumbleweed here, don’t know if they are required though, the above change for sure is. It broke mail receiving/fetching though, had to roll back and haven’t had time to investigate yet.

Update: The below tutorials seem to lack the proper apt-get line, well here it is: sudo apt-get install dovecot-imapd dovecot-pop3d postfix-mysql

Update: Also make sure you have localhost in your /etc/hosts for smtp to work properly!

This is the first time I’ve seriously tried and actually managed to setup a mail server with all the bells and whistles like MySQL based storage of virtual users and passwords, authenticated SMTP relay (mail users can send via SMTP), POP3 and IMAP fetch of mail.

A big part of this massive success has got to do with the fact that I’m now using for instance Postfix 2.7 (apparently >= 2.3 is what you want to have, check which version you have with: postconf -d mail_version).

I first started out with this how to forge tutorial before I found what is probably the best linux email admin tutorial on the net, the ISPmail tutorial by Christoph Haas.

This development left me with a non ISPmail like setup when it comes to the mail directories which in my case looks like this: /var/spool/ where the email address looks like this: My mail user is also not called vmail but virtual.

Apart from that my setup does not differ from the ISPmail setup, below I merely show my, and dovecot.conf as that is something I find lacking with the ISPmail tutorial. You go through it never knowing if the reason for a problem you have is due to the fact that your own setup might differ in ways that are not discussed.

Therefore you have it below, the below config works but might not be optimized in various ways, like avoiding spam filters on outgoing mail for instance. My knowledge of these things are too limited to tell at the moment. This is a good start anyway.

In going through the ISPmail tutorial and you erase your /var/log/mail.log file and logging stops working you can get it running again by running: restart rsyslog.

myhostname =
mydomain =
mydestination = $myhostname, localhost.$mydomain, localhost
myorigin =
mynetworks =
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
mailbox_size_limit = 0
recipient_delimiter = +
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001

There is not much to add to the above, after creating the virtual user you can check what the GID and UID is by running id virtual. The value is needed to allow code/scripts like Zend Mail (my preferred PHP email library) to send emails.

pickup    fifo  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
	-o smtp_fallback_relay=
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix	-	n	n	-	2	pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/
  ${nexthop} ${user}
dovecot   unix  -       n       n       -       -       pipe
    flags=DRhu user=virtual:virtual argv=/usr/lib/dovecot/deliver -d ${recipient}

The above is basically default except for the two last rows which were added in the process of completing the ISPmail tutorial.

protocols = imap imaps pop3 pop3s
disable_plaintext_auth = no
log_timestamp = "%Y-%m-%d %H:%M:%S "
mail_location = /var/spool/vmail/%d/%n
mail_privileged_group = mail

protocol imap {

protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv

protocol managesieve {


protocol lda {
  log_path = /var/spool/vmail/dovecot-deliver.log
  auth_socket_path = /var/run/dovecot/auth-master
  postmaster_address =
  mail_plugins = sieve

auth default {
  mechanisms = plain login
  passdb sql {
    args = /etc/dovecot/dovecot-sql.conf
  userdb passwd {


  userdb static {
    args = uid=1001 gid=1001 home=/var/spool/vmail/%d/%n allow_all_users=yes

  user = root
  socket listen {
    master {
        path = /var/run/dovecot/auth-master
        mode = 0600
        user = virtual

    client {
        path = /var/spool/postfix/private/auth
        mode = 0660
        user = postfix
        group = postfix
  !include_try /etc/dovecot/auth.d/*.auth

dict {


plugin {


Also basically default with additions prescribed by the ISPmail tutorial, except for this line:

args = uid=1001 gid=1001 home=/var/spool/vmail/%d/%n allow_all_users=yes

It reflects my directory structure as explained above and my different uid and gid.

Note also the mail_plugins = sieve line, it’s not cmusieve like in the tutorial.

The /etc/dovecot/dovecot-sql.conf file:

driver = mysql
connect = host= dbname=mailserver user=root password=1234
default_pass_scheme = PLAIN-MD5
password_query = SELECT email as user, password FROM virtual_users WHERE email='%u'

After going through the whole procedure on a new server I got this cryptic message in my /var/log/mail.log from the dovecot startup process:
dovecot: auth(default): Fatal: Socket already exists: /var/spool/postfix/private/auth
dovecot: dovecot: Fatal: Auth process died too early - shutting down

Commenting everything but the first mechanism statement in the file in /etc/dovecot/auth.d/ (mine is called 01-mail-stack-delivery.auth) took care of that problem.

Note that startup problems might be visible in /var/log/mail.log while runtime errors can be found in /var/log/mail.err.

Related Posts

Tags: , , ,