1

I've installed a Postfix-Dovecot mail server following a guide (How to Set Up an Email Server With Postfix, Dovecot and MySQL) that defines a simple setup with virtual mailboxes and a database that maps virtual domains, virtual users and virtual aliases.

Below, the server domain is called server.com. The mail server handles also another domain, here called example.com.

[email protected] has an alias, [email protected]. This is what happens:

  1. mail from [email protected] to [email protected]: delivered
  2. mail from [email protected] to [email protected]: delivered
  3. mail [email protected] to [email protected]: rejected

In the last case the reply is:

554 5.7.1 <[email protected]>: Recipient address rejected: Unknown user

In other words, the alias receives messages only from local mailboxes.

The recipient restrictions are the following:

smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_non_fqdn_recipient,
        reject_unknown_recipient_domain,
        reject_unlisted_recipient,
        reject_unauth_destination,
        check_policy_service inet:localhost:12345

1 Answer 1

0

So far this problem seems to be reported only once here, where the cause was identified in the Dovecot quota check.

In this case it's the last of the smtpd_recipient_restrictions :

check_policy_service inet:localhost:12345

Actually, the problem disappears after removing it.

When the quota check is in place, the log reveals the following:

dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Started userdb lookup
dovecot: auth: master in: USER#0111#[email protected]#011service=quota-status
dovecot: auth: static([email protected]): Performing userdb lookup
dovecot: auth: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Handling PASSL request
dovecot: auth-worker: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: sql([email protected]): query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]';
dovecot: auth-worker: sql([email protected]): unknown user
dovecot: auth-worker: sql([email protected]): Finished passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Finished
dovecot: auth: sql([email protected]): Finished passdb lookup
dovecot: auth: static([email protected]): Finished userdb lookup
dovecot: auth: userdb out: NOTFOUND#0111
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): auth USER input: 
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Userdb lookup failed
postfix/smtpd: NOQUEUE: reject: 554 5.7.1 <[email protected]>: Recipient address rejected: Unknown user; from=<mymailgmail.com> to=<[email protected]>

The problem is that query defined in etc/dovecot/dovecot-sql.conf.ext searches the email only in the virtual_users table:

query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]';

The Linode tutorial referenced above states at some point:

To use an alias as the username:

Add the alias as the source and destination email address to the virtual_aliases table. Change the /etc/dovecot/dovecot-sql.conf.ext file’s password_query value to:

   password_query = SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source = '%u');

I opted for a slightly different solution, making an UNION of the two queries in order to search a virtual user first, then a virtual alias:

password_query = SELECT email as user, password FROM virtual_users WHERE email='%u' \
 UNION SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source = '%u');

This works just fine. Below is an excerpt of the log:

dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Started userdb lookup
dovecot: auth: master in: USER#0114#[email protected]#011service=quota-status
dovecot: auth: static([email protected]): Performing userdb lookup
dovecot: auth: sql([email protected]): Performing passdb lookup
dovecot: auth: sql([email protected]): username changed [email protected] -> [email protected]
dovecot: auth: sql([email protected]): Finished passdb lookup
dovecot: auth: static([email protected]): Finished userdb lookup
dovecot: auth: userdb out: USER#0114#[email protected]#011uid=5000#011gid=5000#011home=/var/mail/vhosts/example.com/mail
dovecot: auth-worker: conn unix:auth-worker: Handling PASSL request
dovecot: auth-worker: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: sql([email protected]): query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]' UNION SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source='[email protected]');
dovecot: auth-worker: sql([email protected]): username changed [email protected] -> [email protected]
dovecot: auth-worker: sql([email protected]): Finished passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Finished
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): auth USER input: [email protected] uid=5000 gid=5000 home=/var/mail/vhosts/example.com/mail
dovecot: quota-status([email protected]): auth-master: userdb lookup([email protected]): Finished userdb lookup
dovecot: quota-status([email protected]): changed username to [email protected]
dovecot: quota-status([email protected]): Effective uid=5000, gid=5000, home=/var/mail/vhosts/example.com/mail
dovecot: lmtp([email protected]): auth-master: userdb lookup([email protected]): Started userdb lookup
dovecot: lmtp([email protected]): auth-master: userdb lookup([email protected]): auth USER input: [email protected] uid=5000 gid=5000 home=/var/mail/vhosts/example.com/mail
dovecot: lmtp([email protected]): auth-master: userdb lookup([email protected]): Finished userdb lookup
dovecot: auth: master in: USER#0112#[email protected]#011service=lmtp
dovecot: auth: static([email protected]): Performing userdb lookup
dovecot: auth: sql([email protected]): Performing passdb lookup
dovecot: auth: sql([email protected]): Finished passdb lookup
dovecot: auth: static([email protected]): Finished userdb lookup
dovecot: auth: userdb out: USER#0112#[email protected]#011uid=5000#011gid=5000#011home=/var/mail/vhosts/example.com/mail
dovecot: auth-worker: conn unix:auth-worker: Handling PASSL request
dovecot: auth-worker: sql([email protected]): Performing passdb lookup
dovecot: auth-worker: sql([email protected]): query: SELECT email as user, password FROM virtual_users WHERE email='[email protected]' UNION SELECT email as user, password FROM virtual_users WHERE email=(SELECT destination FROM virtual_aliases WHERE source='[email protected]');
dovecot: auth-worker: sql([email protected]): Finished passdb lookup
dovecot: auth-worker: conn unix:auth-worker: Finished
dovecot: lmtp([email protected]): lmtp-server: conn unix: rcpt [email protected]: Effective uid=5000, gid=5000, home=/var/mail/vhosts/example.com/mail
dovecot: lmtp([email protected]): lmtp-server: conn unix: rcpt [email protected]: Mailbox INBOX: Mailbox opened because: lib-lda delivery
dovecot: lmtp([email protected]): saved mail to INBOX
postfix/lmtp: to=<[email protected]>, orig_to=<[email protected]>, relay=server.example.com[private/dovecot-lmtp], status=sent

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .