You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postfix+Dovecot邮件服务器收信失败:虚拟别名表用户未知

Let's break down this error first: Recipient address rejected: User unknown in virtual alias table tells us that Postfix isn't finding a matching entry for your recipient in the virtual alias (or linked mailbox) lookup tied to your PostgreSQL tables. Since sending works, your outbound setup is solid—we just need to fix the inbound virtual recipient matching.

Here's a step-by-step troubleshooting plan tailored to your setup:

1. Verify Postfix Core Virtual Configuration in main.cf

First, ensure your main.cf correctly connects Postfix to your PostgreSQL mappings. You should have lines like this (adjust paths to match your setup):

# Define which domains are managed by virtual mailboxes
virtual_mailbox_domains = pgsql:/etc/postfix/pgsql-virtual-mailbox-domains.cf
# Or list domains directly if you don't use a DB for domains: virtual_mailbox_domains = yourdomain.com

# Map aliases to actual mailboxes
virtual_alias_maps = pgsql:/etc/postfix/pgsql-virtual-aliases.cf

# Map mailbox users to their maildir storage paths
virtual_mailbox_maps = pgsql:/etc/postfix/pgsql-virtual-mailbox.cf

# Route virtual mail to Dovecot for delivery
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1

Critical Check: If virtual_mailbox_domains doesn't include your recipient's domain, Postfix will ignore all virtual mappings and look for local system users—this is a common cause of the "user unknown" error.

2. Validate PostgreSQL Virtual Alias Query (pgsql-virtual-aliases.cf)

Your alias lookup needs to correctly match the incoming recipient address to a valid destination mailbox. Check the query syntax in your config:

# Example pgsql-virtual-aliases.cf
user = postfix
password = your_postgres_postfix_password
hosts = localhost
dbname = mail_database
# Use this if your table stores full email addresses as aliases:
query = SELECT destination FROM virtual_aliases WHERE alias='%s' AND active = 1;
# Use this if your table splits local part and domain into separate columns:
# query = SELECT destination FROM virtual_aliases WHERE local_part='%u' AND domain='%d' AND active = 1;

Test the Query: Run this command to see if Postfix can find the recipient:

postmap -q "user@yourdomain.com" pgsql:/etc/postfix/pgsql-virtual-aliases.cf

If this returns nothing, one of these is true:

  • The alias entry doesn't exist in your virtual_aliases table
  • Your query uses incorrect column names (double-check your PostgreSQL table schema)
  • The active flag for the entry is set to 0 (marked inactive)

3. Validate PostgreSQL Mailbox Query (pgsql-virtual-mailbox.cf)

Even if aliases are configured correctly, Postfix needs to confirm the destination mailbox exists. Check your mailbox lookup config:

# Example pgsql-virtual-mailbox.cf
user = postfix
password = your_postgres_postfix_password
hosts = localhost
dbname = mail_database
# Use this if your table stores full email addresses as usernames:
query = SELECT maildir FROM virtual_mailboxes WHERE username='%s' AND active = 1;
# Use this if your table splits local part and domain:
# query = SELECT maildir FROM virtual_mailboxes WHERE local_part='%u' AND domain='%d' AND active = 1;

Test the Query:

postmap -q "user@yourdomain.com" pgsql:/etc/postfix/pgsql-virtual-mailbox.cf

This should return a valid maildir path (e.g., yourdomain.com/user/). If not, fix the query or add the user entry to your virtual_mailboxes table.

4. Check PostgreSQL Permissions

Make sure the postfix database user has SELECT access to your virtual tables:

-- Run this in PostgreSQL as a superuser
GRANT SELECT ON virtual_aliases, virtual_mailboxes TO postfix;

Without this permission, Postfix can't read the tables, leading to empty lookup results.

5. Dig into Postfix Logs for Clues

Check your mail log (usually /var/log/mail.log or /var/log/maillog) for detailed error context:

grep "user@yourdomain.com" /var/log/mail.log

Look for lines like:

postfix/virtual[12345]: warning: pgsql:/etc/postfix/pgsql-virtual-aliases.cf: query failed: FATAL: password authentication failed for user "postfix"
Or:
postfix/virtual[12345]: NOQUEUE: reject: RCPT from mail-oi1-f179.google.com[209.85.167.179]: 550 5.1.1 user@yourdomain.com: Recipient address rejected: User unknown in virtual alias table; from=yourgmail@gmail.com to=user@yourdomain.com proto=ESMTP helo=<mail-oi1-f179.google.com>

These logs will tell you if the issue is a database connection error, missing data, or a misconfigured query.

6. Quick Fix for Direct Mailboxes (No Aliases)

If you don't use aliases and want to map user@domain.com directly to a mailbox, update main.cf to include mailbox maps in recipient checks:

virtual_recipient_maps = $virtual_alias_maps, $virtual_mailbox_maps

This tells Postfix to verify recipients against both aliases and mailbox entries.

After making changes, reload Postfix to apply them:

postfix reload

Then send a test email from Gmail again to verify the fix.

内容的提问来源于stack exchange,提问作者Hauke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:05:42