Make Postfix talk to Dovecot

In a previous chapter we made sure that Postfix knows which emails it's allowed to receive. Now what to do with the email? It has to be stored to disk. Usually that's done by Postfix itself which comes with a very basic mail delivery agent (MDA) called "virtual" that just saves incoming emails to virtual mailboxes on your hard disk. But as we will use Dovecot (for IMAP and POP3 access) anyway we can use its more featureful "local delivery agent" (also known as "Dovecot LDA"). It even allows you to use rules to run different automatic actions on incoming email. To make Postfix use that agent you will have to add a service to your /etc/postfix/master.cf:

dovecot unix - n n - - pipe
  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient}

(Note: the second line has to be indented by spaces!)

Restart Postfix:

postfix reload

Also make Postfix use that service for virtual delivery by adding these lines to your /etc/postfix/main.cf:

postconf -e virtual_transport=dovecot
postconf -e dovecot_destination_recipient_limit=1

So now Postfix will pass on incoming emails to virtual users to the /usr/lib/dovecot/deliver program.

26 Comments

mailbox_command

Great tutorial, many thanks. But I had a problem with an error occured "User unknown" if the user was not established on the sys but only in the db named mailserver. After changing the default entry "mailbox_command = procmail -a "$EXTENSION"" to "mailbox_command = /usr/lib/dovecot/deliver" in main.cf it works fine. Others here with the same problem? Greetings Oliver

Possible change...

Just a quick change, when you say...

Also make Postfix use that service for virtual delivery by adding these lines to your /etc/postfix/main.cf

You imply that you add the postconf -e **** to the conf file, whereas you're really saying, run postconf -e which will add the following to the conf file.


Sorry, just tripped me up a tit.

Thanks!

Thanks for this comment, couldn't figure out what was wrong with my configuration. Maybe the author of this article could clarify this. After executing the commands the main.cf file now has the extra lines:

virtual_transport = dovecot
dovecot_destination_recipient_limit = 1

Having a problem with main.cf

Hi There can anyone help me with this problem?

I'm getting this error when running postfix reload

root@mailman:~# postfix reload
postfix: fatal: /etc/postfix/main.cf, line 44: missing '=' after attribute name: "postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf"

I've checked the main.cf and it looks correct, I restored a backup file and re-did the commands (copy and pasted from the site) and still got the error.

 

Here's a listing of main.cf, with line 44 in bold

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
postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf

postconf -e virtual_transport=dovecot
postconf -e dovecot_destination_recipient_limit=1

I did notice there are spaces before and after all = signs but not with the postconf commands. I tried adding them but it didn't make a difference.

I'm sure it's something silly I just can't spot it.

Still inside

It is still in the tutorial ;-)

Thanks to these comments i could fix it.

Thx for the great tutorial! Until now everything works fine!

Thanks for your reply. Here's

Thanks for your reply. Here's the mail.log excerpt. Don't be surprised, I only did a search and replace on the domain123 and abcdefg.com. 

 

Aug  7 15:30:15 domain123 postfix/pickup[7022]: F0171A02A6: uid=0 from=<root>
Aug  7 15:30:15 domain123 postfix/cleanup[7077]: F0171A02A6: message-id=<20110807133015.F0171A02A6@domain123>
Aug  7 15:30:15 domain123 postfix/qmgr[7027]: F0171A02A6: from=<root@domain123.abcdefg.com>, size=449, nrcpt=1 (queue active)
Aug  7 15:30:16 domain123 postfix/trivial-rewrite[7078]: warning: do not list domain domain123.abcdefg.com in BOTH mydestination and virtual_mailbox_domains
Aug  7 15:30:16 domain123 postfix/local[7080]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Aug  7 15:30:16 domain123 postfix/local[7080]: F0171A02A6: to=<webmaster@domain123.abcdefg.com>, relay=local, delay=0.04, delays=0.03/0.01/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Aug  7 15:30:16 domain123 postfix/qmgr[7027]: F0171A02A6: removed
 

problems with postfix and dovecot

i already tried some tweaks on this before i found this tutorial, so probably my fault is somwhere in the things i changed before i found this...

i am a linux noob, need to make a mail server for school task, so i have no clue what i changed before and where etc...

 

in my mail.log i get the following error (entire log gets spammed by this message every millisecond) :


Nov  6 04:56:14 xxx postfix/qmgr[8452]: B58CD2918A73: from=<check@xxx.be>, size=293, nrcpt=1 (queue active)
Nov  6 04:56:14 xxx postfix/virtual[11138]: B8F8C2918AFB: to=<user1@xxx.xxx.be>, relay=virtual, delay=202553, delays=202553/0/0/0, dsn=4.2.0, status=deferred (delivery failed to mailbox /var/mail/vhosts/1: unable to create lock file /var/mail/vhosts/1.lock: Permission denied)
 

first of all, i have no clue why it points me to /var/mail/vhosts folder... and what the 1 means , i don't know either.. Aswell in the first line it shows from check@xxx.be, while it should be i think from check@xxx.xxx.be , cause my domain is the same everywhere

 

 

then my dovecot problem i got this :

Nov  6 14:25:47 xxx pipe[14400]: fatal: pipe_command: execvp /user/lib/dovecot/deliver: No such file or directory
 

 

 

Help please !!

mail transport unavailable

Hi can anyone help me with this problem?

I'm getting this error when sending a message :

 

  postfix/error[11403]: 692A94C1CA: to=<test@rede.local>, relay=none, delay=0.09, delays=0.08/0/0/0, dsn=4.3.0, status=deferred (mail transport unavailable)

 

 
 

status=deferred (temporary failure)

 

         last upgrade error : 

         postfix/pipe[16214]: 5B76C4C1EB: to=<teste2@rede.local>, relay=dovecot, delay=306, delays=306/0.03/0/0.39, dsn=4.3.0, status=deferred (temporary failure)
 

        

Really helpful

Hi,

 

This is one of the articles that, after struggling hours with postfix, virtual mailboxes and so on and so forth help to finish the work and go home.

Thank you very much!

Ramon Araujo

delimiter problems

Hi!

First, thanks for a great guide. 

Lately I've been trying to start using delimiter in my email address for various online sites, being able to trace who's leaking / selling my email. At first I could not get this to work, even though postfix' main.cf file included: recipient_delimiter = + , I got "user not found" in my logs, and the email was bounced. After some research it became clear that dovecot was not aware of the delimiter setting in postfix.

By changing this line in master.cf 

flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${recipient}

to 

flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}

Dovecot was able to deliver emails to user+sometag@example.com to user's mailbox. Maybe you could update the guide, unless there are some other reasons to use ${recipient} instead of ${user}@${nexthop}?

Thanks again for a great guide.

 

Erik Forsén

Thanks. This solved my

Thanks. This solved my problem as well. I also wonder if there are any other reasons behind using recipient variable. Would be probably beneficial to include this in the guide.

SMTP time out?

I can't for the life of me figure out why external clients (Thunderbird etc) cant send mail using smtp and ssl.. I can read fine, and it's not a firewall issue... mail.log simply shows a time out even w/ auth_verbose...

Heres my dovecot and postfix.. hopefuly my attempts to fix havent messed things up to bad.

dovecot -n

# 1.2.15: /etc/dovecot/dovecot.conf
# OS: Linux 2.6.32-308.8.2.el5.028stab101.1 i686 Debian 6.0.6 simfs
log_timestamp: %Y-%m-%d %H:%M:%S
protocols: imaps pop3s
ssl: required
disable_plaintext_auth: no
login_dir: /var/run/dovecot/login
login_executable(default): /usr/lib/dovecot/imap-login
login_executable(imap): /usr/lib/dovecot/imap-login
login_executable(pop3): /usr/lib/dovecot/pop3-login
mail_privileged_group: mail
mail_location: maildir:/var/vmail/%d/%n/Maildir
mbox_write_locks: fcntl dotlock
mail_executable(default): /usr/lib/dovecot/imap
mail_executable(imap): /usr/lib/dovecot/imap
mail_executable(pop3): /usr/lib/dovecot/pop3
mail_plugin_dir(default): /usr/lib/dovecot/modules/imap
mail_plugin_dir(imap): /usr/lib/dovecot/modules/imap
mail_plugin_dir(pop3): /usr/lib/dovecot/modules/pop3
lda:
auth_socket_path: /var/run/dovecot/auth-master
postmaster_address: root@thedomain.com
mail_plugins: sieve
log_path:
auth default:
mechanisms: plain login
passdb:
driver: sql
args: /etc/dovecot/dovecot-sql.conf
userdb:
driver: passwd
userdb:
driver: static
args: uid=5000 gid=5000 home=/var/vmail/%d/%n allow_all_users=yes
socket:
type: listen
client:
path: /var/spool/postfix/private/auth
mode: 432
user: postfix
group: postfix
master:
path: /var/run/dovecot/auth-master
mode: 384
user: vmail

postconf -n

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix
inet_interfaces = all
mailbox_size_limit = 0
mydestination = mail.thedomain.com, localhost.com, , localhost
myhostname = thedomain.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf,mysql:/etc/postfix/mysql-email2email.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = dovecot