Postfix

使用簡單過濾時,後綴替換“來自”

  • February 14, 2015

我正在嘗試配置 Postfix(在 RHEL 6.5 上)以修改傳入消息的內容並將電子郵件轉發到遠端伺服器。我使用通過管道傳輸到 Postfix 的 Perl 腳本來修改內容,然後使用 Sendmail 將電子郵件注入回 Postfix。

當電子郵件第一次到達伺服器時,我看到該from欄位被正確初始化,但隨後它被重寫:

postfix/smtpd[29150]: connect from ** local domain **[x.x.x.x]
postfix/smtpd[29150]: 2CF665F6B9: client=** local domain **[x.x.x.x]
postfix/cleanup[29155]: 2CF665F6B9: message-id=<msg_172345>
postfix/qmgr[29120]: 2CF665F6B9: from=<original_sender@external.domain>, size=66895, nrcpt=1 (queue active)
postfix/pickup[29119]: 472C75F6BC: uid=600 from=<admin>
postfix/cleanup[29155]: 472C75F6BC: message-id=<msg_172345>
postfix/pipe[29159]: 2CF665F6B9: to=<correct_recipient@external.domain>, relay=myhook, delay=3.1, delays=3/0.01/0/0.06, dsn=2.0.0, status=sent (delivered via myhook service)
postfix/qmgr[29120]: 2CF665F6B9: removed
postfix/qmgr[29120]: 472C75F6BC: from=<admin@** local domain **>, size=67025, nrcpt=1 (queue active)

如您所見,該from欄位從original_sender@external.domain變為admin@** local domain **

我假設它admin來自user=adminmain.cf 中的管道,而本地域來自/etc/hosts.

我在這裡需要的是保留電子郵件的原始發件人,但似乎我無法做到這一點。你能指出我正確的方向嗎?

非常感謝。

編輯:

這是我的 Postfix 配置:

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
header_checks = regexp:/etc/postfix/header_checks
html_directory = no
inet_interfaces = $myhostname, localhost
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
myhostname = ** local domain **
newaliases_path = /usr/bin/newaliases.postfix
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
smtp_connection_cache_on_demand = yes
smtpd_helo_required = no
transport_maps = hash:/etc/postfix/transport
unknown_local_recipient_reject_code = 550

看來我的 Postfix 不接受該-M標誌。

這是master.cf

# cat /etc/postfix/master.cf | grep -v "#"
smtp      inet  n       -       n       -       -       smtpd 
 -o content_filter=myhook:
pickup    fifo  n       -       n       60      1       pickup
cleanup   unix  n       -       n       -       0       cleanup
qmgr      fifo  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       n       1000?   1       tlsmgr
rewrite   unix  -       -       n       -       -       trivial-rewrite
bounce    unix  -       -       n       -       0       bounce
defer     unix  -       -       n       -       0       bounce
trace     unix  -       -       n       -       0       bounce
verify    unix  -       -       n       -       1       verify
flush     unix  n       -       n       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       n       -       -       smtp
relay     unix  -       -       n       -       -       smtp
       -o smtp_fallback_relay=
showq     unix  n       -       n       -       -       showq
error     unix  -       -       n       -       -       error
retry     unix  -       -       n       -       -       error
discard   unix  -       -       n       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       n       -       -       lmtp
anvil     unix  -       -       n       -       1       anvil
scache    unix  -       -       n       -       1       scache
myhook unix - n n - - pipe
  flags=Rq user=admin argv=/var/tmp/filter.pl ${sender} ${recipient}

根據上面的輸出master.cf,我們知道後綴將在腳本的第一個參數上傳遞原始發件人。因此,您的腳本必須解析參數,將其保存到變數中,並在通過 sendmail 命令將電子郵件重新註入後綴時使用它來提供發件人地址。

Sendmail 命令通過 -f 參數接受發件人參數。所以你的腳本必須呼叫sendmail -f $origsender ...other parameter

參考資料: http ://www.postfix.org/FILTER_README.html#simple_filter

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