Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2013 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7332276 to your computer and use it in GitHub Desktop.
Save anonymous/7332276 to your computer and use it in GitHub Desktop.
Postfix delivers to maildir instead of Dovecot LDA for a virtual user
Hi
I have been able to setup postfix and dovecot using postgres as the backend store with virtual user maps on Ubuntu 12.04 LTS Server.
I have been following instructions from here: http://wiki2.dovecot.org/HowTo/DovecotPostgresql
I haven't setup postfix to use saslauthd and PAM, instead I am using dovecot for SASL authentication. Rest of the table structures and query files are the same as from the wiki.
SASL authentication works correctly for SMTP POP IMAP.
I am able to send emails from a mail client such as Thunderbird with SASL authentication.
However I am not able to receive emails for virtual users. I cannot figure out why. System users are getting their emails in the mail box correctly. Postfix fires the mailbox_command to hand over the mail to dovecot.
This is how my mail.log looks when I send emails from an external domain:
Nov 6 06:48:21 localhost postfix/smtpd[20053]: E075280C52: client=mail-ee0-f41.google.com[74.125.83.41]
Nov 6 06:48:22 localhost postfix/cleanup[20064]: E075280C52: message-id=<CAJ+V0eCU891rSzSMVbcSy4zsRUk5GUp58b70Wv_WgZxLbKuyLw@mail.gmail.com>
Nov 6 06:48:22 localhost postfix/qmgr[17492]: E075280C52: from=<me@gmail.com>, size=3124, nrcpt=1 (queue active)
Nov 6 06:48:22 localhost postfix/virtual[20066]: E075280C52: to=<someone@mydomain.com>, relay=virtual, delay=0.85, delays=0.7/0.02/0/0.13, dsn=2.0.0, status=sent (delivered to maildir)
Nov 6 06:48:22 localhost postfix/qmgr[17492]: E075280C52: removed
Nov 6 06:48:22 localhost postfix/smtpd[20053]: disconnect from mail-ee0-f41.google.com[74.125.83.41]
Postfix seems to deliver the mail to maildir instead of the home directory of the virtual user. Incase of the system user, the logs indicate that the mailbox_command was fired and I do get to see the mail in the inbox.
My postfix main.cf:
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
append_dot_mydomain = no
biff = no
broken_sasl_auth_clients = yes
config_directory = /etc/postfix
dovecot_destination_recipient_limit = 1
inet_interfaces = all
mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/conf.d/01-mail-stack-delivery.conf -m "${EXTENSION}"
mailbox_size_limit = 0
mydestination = localhost, localhost.localdomain, localhost
myhostname = mydomain.com
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
readme_directory = no
recipient_delimiter = +
relayhost =
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtp_use_tls = yes
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_recipient_restrictions = reject_unknown_recipient_domain,
reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated,
reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_path = private/dovecot-auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sender_restrictions = reject_unknown_sender_domain
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /root/certs/www.mydomain.com.pem
smtpd_tls_key_file = /root/certs/www.mydomain.com.key
smtpd_tls_mandatory_ciphers = medium
smtpd_tls_mandatory_protocols = SSLv3, TLSv1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
transport_maps = pgsql:/etc/postfix/transport.cf
virtual_gid_maps = pgsql:/etc/postfix/gids.cf
virtual_mailbox_base = /home
virtual_mailbox_domains = mydomain.com
virtual_mailbox_maps = pgsql:/etc/postfix/mailboxes.cf
virtual_maps = pgsql:/etc/postfix/virtual.cf
virtual_transport = dovecot
virtual_uid_maps = pgsql:/etc/postfix/uids.cf
I have included the virtual_transport parameter to indicate that dovecot is running as LDA. I have also included the pgsql query file in the virtual_mailbox_maps parameter.
My mailboxes.cf file which points the email id of the virtual user to the appropriate mail path:
user=mailreader
password=secret
dbname=mails
table=postfix_mailboxes
select_field=mailbox
where_field=userid
hosts=localhost
My postfix master.cf file:
smtp inet n - n - - smtpd
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
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)
dovecot unix - n n - - pipe
flags=DRhu user=vmailuser:vmailuser argv=/usr/lib/dovecot/deliver -f
${sender} -d ${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/postfix-to-mailman.py
${nexthop} ${user}
I have included the dovecot LDA service line above so that postfix can deliver to virtual users as per: http://wiki2.dovecot.org/LDA/Postfix
This is my doveconf -n output:
# 2.0.19: /etc/dovecot/dovecot.conf
# OS: Linux 3.2.0-24-virtual i686 Ubuntu 12.04 LTS ext4
auth_debug = yes
auth_debug_passwords = yes
auth_mechanisms = plain login digest-md5 cram-md5
auth_verbose = yes
mail_debug = yes
mail_location = maildir:/home/vmailuser/%d/%n/Maildir
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date ihave
passdb {
args = /etc/dovecot/dovecot-sql.conf
driver = sql
}
plugin {
sieve = ~/.dovecot.sieve
sieve_dir = ~/sieve
}
protocols = imap pop3 sieve
service auth {
unix_listener /var/spool/postfix/private/dovecot-auth {
group = postfix
mode = 0660
user = postfix
}
}
ssl_cert = </root/certs/www.mydomain.com.pem
ssl_cipher_list = ALL:!LOW:!SSLv2:ALL:!aNULL:!ADH:!eNULL:!EXP:RC4+RSA:+HIGH:+MEDIUM
ssl_key = </root/certs/www.mydomain.com.key
userdb {
args = /etc/dovecot/dovecot-sql.conf
driver = sql
}
verbose_ssl = yes
protocol imap {
imap_client_workarounds = delay-newmail
mail_max_userip_connections = 10
}
protocol pop3 {
mail_max_userip_connections = 10
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
}
protocol lda {
deliver_log_format = msgid=%m: %$
mail_plugins = sieve
postmaster_address = postmaster
quota_full_tempfail = yes
rejection_reason = Your message to <%t> was automatically rejected:%n%r
}
I have setup mail_location to point to the home directory of vmailuser under which for the given domain the virtual users mail dir is created. However, the mails clearly don't seem to get delivered for the virtual user.
Any help to fix this would be appreciated. Thanks! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment