I have setup postfix to use virtual users for inbound emails, with the configuration read from mysql.

However, when I try to deliver a mail locally, using something like sendmail root@localhost < testmail, the queries are being executed, but the mail is not delivered to the virtual user directory.
The directory /var/mail/root is created instead.

Mysql config seems correct, as the following queries are executed:

SELECT destination FROM aliases WHERE mail='root@localhost' and enabled = 1

| destination    |
| root@localhost |

SELECT destination FROM aliases WHERE mail='localhost' and enabled = 1;
Empty set (0.00 sec)

SELECT domain FROM domains WHERE domain='localhost' and enabled = 1;

| domain    |
| localhost |

But they seem to be ignored.
When trying to login through courier IMAP, this results in the following:

1 login root@localhost <password>
* BYE [ALERT] Fatal error: No such file or directory: No such file or directory

because the folder that postfix created is not the one set in the DB for the user.


(largely inspired from a guide):

alias_database = hash:/etc/postfix/aliases
alias_maps = hash:/etc/postfix/aliases
append_dot_mydomain = no
biff = no
config_directory = /etc/postfix

mynetworks = [::ffff:]/104 [::1]/128
mynetworks_style = host
myorigin = /etc/mailname
readme_directory = no
recipient_delimiter = +

# working relayhost config here

smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, permit
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_sender_restrictions = permit_mynetworks, warn_if_reject reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit

virtual_alias_maps = mysql:/etc/postfix/mysql_alias.cf
virtual_gid_maps = static:5000
virtual_mailbox_base = /var/spool/mail/virtual
virtual_mailbox_domains = mysql:/etc/postfix/mysql_domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_mailbox.cf
virtual_uid_maps = static:5000
  • What is the output (when run as root) of postconf ? – davidgo Mar 17 '14 at 23:23
  • @davidgo it's 900+ lines so can't paste it, but from a quick look it looks right. Any particularly interesting part? – Razor Mar 17 '14 at 23:29
  • I don't know what might be interesting, but it strikes me as rather difficult to try and troubleshoot a Postfix configuration without actually seeing the postfix configuration. Try providing a "postconf -n" which should hopefully be a lot smaller and leave out all the default config stuff. Of particular interest would be the virtual_* stuff and associated files. – davidgo Mar 17 '14 at 23:52

In order to determinate if postfix is actually delivering to a virtual mailbox, you can check the relay value in /var/log/mail.log.

tail -100 /var/log/mail.log | grep relay=

You are most likely seeing relay=local, whereas you want relay=virtual.

This happens because postfix is delivering to local_recipient_maps.
One indication of this issue is that in your log you can see

warning: do not list domain example.com in BOTH mydestination and virtual_mailbox_domains

You can fix this issue by either overwriting mydestination with an empty value:

mydestination = 

or forcing postfix to use virtual transport even for local mailboxes:

local_transport = virtual
local_recipient_maps = $alias_maps $virtual_mailbox_maps

The first option is better because it solves the root problem, rather than hammering it in a quiet corner.

| improve this answer | |

Shouldn't the IMAP server getting the mails directly instead of from the maildir? Or /var/mail/foo?

I use dovecot, and I've setup a lmtp forward socket on which dovecot listens. When new mail arrives, postfix sends it to dovecot socket. The directory etc is all managed by dovecot.

| improve this answer | |
  • I would like to make this work without any extra dependencies such as dovecot if possible. Shouldn't postfix be able to handle virtual directories natively? – Razor Mar 18 '14 at 9:00
  • Can you post the configuration and table data for virtual mailbox maps? I sniff some problem there. Or may be the priority is getting messed up, root@localhost is a valid user and postfix directly delivers instead of looking up the tables. – Nilesh Mar 18 '14 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.