使用简单过滤时,Postfix会replace“from”

我正在尝试configurationPostfix(在RHEL 6.5上)以修改传入邮件的内容并将邮件转发到远程服务器。 我使用一个Perl脚本pipe理Postfix来修改内容,并使用Sendmail将邮件注入到Postfix中。

当电子邮件第一次到达服务器时,我看到from字段被正确初始化,但它被重写:

 postfix/smtpd[29150]: connect from ** local domain **[xxxx] postfix/smtpd[29150]: 2CF665F6B9: client=** local domain **[xxxx] postfix/cleanup[29155]: 2CF665F6B9: message-id=<msg_172345> postfix/qmgr[29120]: 2CF665F6B9: from=<[email protected]>, 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=<[email protected]>, 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字段从[email protected]更改为admin@** local domain **

我假设admin来自main.cf中的pipe user=admin ,本地域来自/etc/hosts

我需要的是保留电子邮件的原始发件人,但似乎我无法做到这一点。 你能把我指向正确的方向吗?

非常感谢。

编辑:

这是我的Postfixconfiguration:

 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 - nn - - local virtual unix - nn - - virtual lmtp unix - - n - - lmtp anvil unix - - n - 1 anvil scache unix - - n - 1 scache myhook unix - nn - - pipe flags=Rq user=admin argv=/var/tmp/filter.pl ${sender} ${recipient} 

根据上面的master.cf的输出,我们知道postfix会在脚本的第一个参数上传递原始的发送者。 所以,你的脚本将不得不分析参数,将其保存到variables,并使用它提供发件人地址,当电子邮件通过sendmail命令重新注入后缀。

Sendmail命令通过-f参数接受发送者参数。 所以你的脚本必须调用sendmail -f $origsender ...other parameter

参考: http : //www.postfix.org/FILTER_README.html#simple_filter