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.
Config
(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 = 127.0.0.0/8 [::ffff:127.0.0.0]/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
In order to determinate if postfix is actually delivering to a virtual mailbox, you can check the
relay
value in/var/log/mail.log
.Try:
You are most likely seeing
relay=local
, whereas you wantrelay=virtual
.This happens because postfix is delivering to
local_recipient_maps
.One indication of this issue is that in your log you can see
You can fix this issue by either overwriting mydestination with an empty value:
or forcing postfix to use virtual transport even for local mailboxes:
The first option is better because it solves the root problem, rather than hammering it in a quiet corner.
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.