Postfix
拒絕使用 Postfix 向特定收件人發送電子郵件
所以,現在我正在嘗試通過
smtpd_recipient_restrictions
.我遇到的問題是,當我期望它們被系統拒絕時,我的測試電子郵件正在發送。
這是
/etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. smtpd_recipient_restrictions = reject_unknown_recipient_domain, reject_unauth_destination, check_recipient_access hash:/etc/postfix/recipient_block myhostname = hostname.domain.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = hostname.domain.com, hostname.domain.com, , localhost relayhost = mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_command = procmail -a "$EXTENSION" mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all
我的
/etc/postfix/recipient_block
(後來通過 postmap 執行)personalemail@anotheroneofmydomains.com REJECT
然後,我像這樣發送測試電子郵件:
$ echo test | mail -s "test email, please ignore" personalemail@anotheroneofmydomains.com
Postfix已經重新載入了它的conf,已經重新啟動了幾次以嘗試排除故障,但都無濟於事。
拖尾
/var/log/mail.log
文件的塊如下所示:Sep 25 02:27:17 antares postfix/master[3024]: reload -- version 2.7.0, configuration /etc/postfix Sep 25 02:27:27 antares postfix/pickup[3104]: C723018770: uid=1001 from=<obsidian> Sep 25 02:27:27 antares postfix/cleanup[3110]: C723018770: message-id=<20110925092727.C723018770@hostname.domain.com> Sep 25 02:27:27 antares postfix/qmgr[3105]: C723018770: from=<obsidian@hostname.domain.com>, size=388, nrcpt=1 (queue active) Sep 25 02:27:28 antares postfix/smtp[3112]: C723018770: to=<personalemail@anotheroneofmydomains.com>, relay=ASPMX.L.GOOGLE.COM[74.125.47.26]:25, delay=0.35, delays=0.01/0.01/0.12/0.21, dsn=2.0.0, status=sent (250 2.0.0 OK 1316942848 j50si8227610yhe.128) Sep 25 02:27:28 antares postfix/qmgr[3105]: C723018770: removed
……所以,我難住了。我不明白為什麼電子郵件沒有被拒絕。
問題是郵件是通過
pickup
服務(通過 sendmail 介面)發送的,因此它是“外發”郵件。對於外發郵件,smtpd_*_restrictions
不適用。這些限制僅適用於通過 SMTP 發送的“傳入”郵件。編輯 Victor Duchovni(Postfix 維護者)甚至提供了一個解決方案:http ://marc.info/?l=postfix-users&m=120155612332393&w=1
正如@mailq 所說,“郵件”程序不會通過 SMTP 注入消息,“smtpd_recipient_restrictions”僅適用於通過 SMTP 接收的消息。因此,例如,如果您執行它,您應該會看到它顯示拒絕:
printf 'ehlo hostname.domain.com\nmail from: <user@domain.com>\nrcpt to:' \ '<personalemail@anotheroneofmydomains.com>\nquit\n' | nc localhost 25
這通過“netcat”(通常稱為“nc”)進行 SMTP 連接,並且應該證明該塊確實到位。
也許這已經足夠了?如果不是,我能想出拒絕這個遠端地址的唯一方法是設置一個拒絕發送給它的消息的傳輸,然後在傳輸表中列出該地址以與拒絕傳輸相關聯。