Nginx – Postfix(admin), Dovecot, MySQL: Aliases not working

debiandovecotMySQLnginxpostfix

I'm able to send mail to the mailboxes i've setup with postfixadmin. This is working correctly and i can send and deliver mail on them. But now i'm in need of Aliases to work properly as well.
I've used a tutorial to set things up listed here. Yet somehow postfix keeps on trying to send the mail to a mailbox for the alias.

Main email: name@domain.nl

Alias email: alias@domain.nl

The records in the database are correctly set and when i'm running this command:

postmap -q alias@domain.nl mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf

i'm retrieving the right emailaddress: name@domain.nl which has a mailbox attached to it.
What am i doing wrong?

The logs don't provide any useful information. When i'm sending a mail to my alias the logs looks like the following:

Jun 10 10:38:13 localhost postfix/smtpd[3061]: C27DC614DD: client=mail-wm0-f41.google.com[74.125.82.41]
Jun 10 10:38:13 localhost postfix/cleanup[3072]: C27DC614DD: message-id=<CAGUk6whj3Drb-c=5N55TU80UoKR6sC2r4k+3jtxj9pBO5Gp5Pg@mail.gmail.com>
Jun 10 10:38:13 localhost postfix/qmgr[30229]: C27DC614DD: from=<some.personal.email@gmail.com>, size=2011, nrcpt=1 (queue active)
Jun 10 10:38:13 localhost postfix/smtpd[3061]: disconnect from mail-wm0-f41.google.com[74.125.82.41]
Jun 10 10:38:14 localhost postfix/smtp[3074]: C27DC614DD: to=<some.personal.email@gmail.com>, orig_to=<alias@domain.nl>, relay=gmail-smtp-in.l.google.com[74.125.136.27]:25, delay=0.32, delays=0.07/0.01/0.15/0.1, dsn=2.0.0, status=sent (250 2.0.0 OK 1465547906 q2si2091788wme.1 - gsmtp)
Jun 10 10:38:14 localhost postfix/qmgr[30229]: C27DC614DD: removed

Yet it doesn't get into the mailbox of name@domain.nl

My /etc/postfix/main.cf:

smtpd_banner = $myhostname ESMTP
biff = no
append_dot_mydomain = no
readme_directory = no

smtpd_tls_cert_file=/etc/letsencrypt/live/domain.nl/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/domain.nl/privkey.pem
smtpd_tls_security_level = may
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtpd_tls_auth_only = yes

smtpd_tls_mandatory_protocols=!SSLv2
smtpd_tls_ciphers = high
smtpd_tls_loglevel = 1
smtpd_tls_ask_ccert=yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions =
    permit_sasl_authenticated
    permit_mynetworks
    reject_unauth_destination
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
myhostname = mail.domain.nl

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $myhostname

mydestination = localhost
relayhost =
mynetworks = 127.0.0.0/8 192.168.0.0/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

disable_vrfy_command = yes
virtual_transport = lmtp:unix:private/dovecot-lmtp
virtual_mailbox_base = /var/mail

virtual_mailbox_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf

virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf

virtual_mailbox_domains = mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf

header_checks = regexp:/etc/postfix/header_checks

My /etc/dovecot/dovecot-sql.conf.ext looks like this:

driver = mysql
connect = host=localhost dbname=postfix user=postfix password=spieard123
default_pass_scheme = MD5-CRYPT
password_query = SELECT username as user, password, '/var/mail/%d/%n' as userdb_home, 'maildir:/var/mail/%d/%n' as userdb_mail, 5000 as userdb_uid, 5000 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'

My /etc/dovecot/conf.d/auth-sql.conf.ext looks like this:

passdb {
  driver = sql
  args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb {
  driver = static
  args = uid=vmail gid=vmail home=/var/mail/%d/%n
}

Chat with NickW.

I've opened up a new room since the one with NickW is frozen. You can join here.

Postfixadmin setup:
Postfix admin

Best Answer

I think the problem is that you're selecting your endpoint from mailbox, not from the virtual users table, so postfix knows where it should go, but not dovecot.

Change :

SELECT username as user, password, '/var/mail/%d/%n' as userdb_home, 'maildir:/var/mail/%d/%n' as userdb_mail, 5000 as userdb_uid, 5000 as userdb_gid FROM mailbox WHERE username = '%u' AND active = '1'

To:

password_query = SELECT email as user, password, '/var/mail/%d/%n' as userdb_home, 'maildir:/var/mail/%d/%n' as userdb_mail, 5000 as userdb_uid, 5000 as userdb_gid FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source = '%u');

Obviously, the DB and table names may vary.. the AND active = '1' shouldn't be necessary since it's not the mailbox table..

Related Topic