Postfix

postfix + virtual users (db) : 添加一個donotreply地址

  • March 28, 2016

我按照DigitalOcean的指南在 Centos 6.5 上設置了 postfix/dovecot/mysql 。

我的虛擬地址和別名工作得很好,現在我正在嘗試添加一個 donotreply 別名。

在我的虛擬使用者表中,我有donotreply@mydomain.com一個目標為devnull.

最後/etc/aliases我有

devnull: /dev/null

我追newaliases了這個。

檢查虛擬別名:

$ postmap -q donotreply@mydomain.com mysql:/etc/postfix/mysql-virtual-alias-maps.cf 
devnull

當我向此地址發送郵件時,我收到“使用者不存在”的退回郵件devnull@mydomain.com

Mar 25 14:48:12 vps1 postfix/lmtp[7686]: 8543360392: to=<devnull@mydomain.com>, orig_to=<donotreply@mydomain.com>, relay=host.mydomain.com[private/dovecot-lmtp], delay=0.14, delays=0.07/0.01/0.01/0.05, dsn=5.1.1, status=bounced (host host.mydomain.com[private/dovecot-lmtp] said: 550 5.1.1 <devnull@mydomain.com> User doesn't exist: devnull@mydomain.com (in reply to RCPT TO command))

每次更改後都重新載入了 Postfix(和 dovecot),但仍然沒有運氣。

我的後綴配置:

$ postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
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
milter_default_action = accept
milter_protocol = 2
mydestination = localhost
myhostname = host.mydomain.com
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
non_smtpd_milters = $smtpd_milters
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_milters = inet:127.0.0.1:8891
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /path/to/ssl/cert
smtpd_tls_key_file = /path/to/ssl/privatekey
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 550
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp

我還嘗試在 /etc/postfix/main.cf 中啟用本地收件人映射

local_recipient_maps = unix:passwd.byname $alias_maps

但這也沒有用。

我還創建了一個 devnull 本地使用者

$ useradd -M -d /dev/null -s /sbin/nologin devnull

但這也沒有改變。

如何獲得一個虛擬別名以重定向到 /dev/null?

您也可以使用DISCARD

丟棄可選文本…

聲明成功傳遞並靜默丟棄消息。如果指定,則記錄可選文本,否則記錄一般消息。

smtpd_recipient_restrictions =
check_recipient_access hash:/etc/postfix/virtual_access
reject_unknown_recipient_domain
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination

# cat virtual_access
no-reply@example.net DISCARD DEV-NULL

# postmap virtual_access

發送簡單的消息

# echo "Hello world" | swaks -4 --server localhost --from alex@example.net --to no-reply@example.net --h-Subject "Test message" --body -
=== Trying localhost:25...
=== Connected to localhost.
<-  220 smtp.example.net ESMTP Postfix
-> EHLO jenkins.example.net
<-  250-smtp.example.net
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-AUTH LOGIN PLAIN
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250 DSN
-> MAIL FROM:<alex@example.net>
<-  250 2.1.0 Ok
-> RCPT TO:<no-reply@example.net>
<-  250 2.1.5 Ok
-> DATA
<-  354 End data with <CR><LF>.<CR><LF>
-> Date: Mon, 28 Mar 2016 09:09:50 +0000
-> To: no-reply@example.net
-> From: alex@example.net
-> Subject: Test message
-> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
->
-> Hello world
->
->
-> .
<-  250 2.0.0 Ok: queued as 835721C7EBD
-> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.

檢查郵件日誌

Mar 28 09:09:46 ci postfix/postfix-script[16971]: starting the Postfix mail system
Mar 28 09:09:46 ci postfix/master[16972]: daemon started -- version 2.6.6, configuration /etc/postfix
Mar 28 09:09:50 ci postfix/smtpd[16978]: connect from localhost[127.0.0.1]
Mar 28 09:09:50 ci postfix/smtpd[16978]: NOQUEUE: discard: RCPT from localhost[127.0.0.1]: <no-reply@example.net>: Recipient address DEV-NULL; from=<alex@example.net> to=<no-reply@example.net> proto=ESMTP helo=<jenkins.example.net>
Mar 28 09:09:50 ci postfix/smtpd[16978]: 835721C7EBD: client=localhost[127.0.0.1]
Mar 28 09:09:50 ci postfix/smtpd[16978]: disconnect from localhost[127.0.0.1]

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