Mysql

後綴不尊重 mysql 別名域

  • June 27, 2017

所以設置是使用 postfix、dovecot、postfixadmin 和 mysql。我已經將後綴管理員配置為一個域的別名,“name.co.uk”到“name.net”,我在數據庫中看到了這個,所以那裡沒有問題。但是,當發送郵件到“name.co.uk”時,它不會發送到“name.net”,我可以看到它沒有出現在郵箱中,而是放在虛擬郵件目錄中舊域(一開始就不應該存在!)。通過日誌文件,它似乎根本沒有考慮別名。

#~ postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
dovecot_destination_recipient_limit = 1
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 30720000
mydestination = localhost, localhost.localdomain
myhostname = company.net
mynetworks = 127.0.0.0/8
newaliases_path = /usr/bin/newaliases.postfix
policyd-spf_time_limit = 3600
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, check_policy_service unix:private/policyd-spf
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_CAfile = /etc/letsencrypt/live/mail.company.net/cert.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.company.net/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.company.net/privkey.pem
smtpd_tls_loglevel = 3
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
unknown_local_recipient_reject_code = 550
virtual_alias_domains = mysql:/etc/postfix/mysql_virtual_alias_domains_catchall_maps.cf, mysql:/etc/postfix/mysql_virtual_alias_domains_mailbox_maps.cf, mysql/etc/postfix/mysql_virtual_alias_domains_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_minimum_uid = 5000
virtual_transport = dovecot
virtual_uid_maps = static:5000

然後在配置文件中

#~ for name in /etc/postfix/mysql_virtual_*; do echo $name && cat $name; done
/etc/postfix/mysql_virtual_alias_domains_catchall_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query  = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
/etc/postfix/mysql_virtual_alias_domains_mailbox_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'
/etc/postfix/mysql_virtual_alias_domains_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
/etc/postfix/mysql_virtual_alias_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
table = alias
select_field = goto
where_field = address
/etc/postfix/mysql_virtual_domains_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
table = domain
select_field = domain
where_field = domain
#additional_conditions = and backupmx = '0' and active = '1'
/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
table = mailbox
select_field = quota
where_field = username
#additional_conditions = and active = '1'
/etc/postfix/mysql_virtual_mailbox_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'

問題解決了。:proxy之前失踪:mysql

新的配置文件

alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
broken_sasl_auth_clients = yes
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
dovecot_destination_recipient_limit = 1
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
message_size_limit = 30720000
mydestination = localhost, localhost.localdomain
myhostname = company.net
mynetworks = 127.0.0.0/8
newaliases_path = /usr/bin/newaliases.postfix
policyd-spf_time_limit = 3600
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination, check_policy_service unix:private/policyd-spf
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_CAfile = /etc/letsencrypt/live/mail.company.net/cert.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.company.net/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.company.net/privkey.pem
smtpd_tls_loglevel = 3
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
unknown_local_recipient_reject_code = 550
virtual_alias_maps = proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf, proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
virtual_mailbox_limit = 51200000
virtual_mailbox_maps = proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf, proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
virtual_minimum_uid = 5000
virtual_transport = dovecot
virtual_uid_maps = static:5000

/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
# mysql_virtual_alias_domain_catchall_maps.cf
# handles catch-all settings of target-domain
user = mail_admin
password = password
hosts = localhost
dbname = mail
query  = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'

/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf
# mysql_virtual_alias_domain_mailbox_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'

/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf
# mysql_virtual_alias_domain_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'

/etc/postfix/sql/mysql_virtual_alias_maps.cf
# mysql_virtual_alias_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
#expansion_limit = 100

/etc/postfix/sql/mysql_virtual_domains_maps.cf
# mysql_virtual_domains_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query          = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
#query          = SELECT domain FROM domain WHERE domain='%s'
#optional query to use when relaying for backup MX
#query           = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'
#expansion_limit = 100

/etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf
# mysql_virtual_mailbox_limit_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'

/etc/postfix/sql/mysql_virtual_mailbox_maps.cf
# mysql_virtual_mailbox_maps.cf
user = mail_admin
password = password
hosts = localhost
dbname = mail
query           = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1'
#expansion_limit = 100

引用自:https://serverfault.com/questions/858089