我正在尝试通过 Postfix 将电子邮件传输到我拥有的 Python 脚本。目前,有多个收件人的消息会为每个收件人传输一次到脚本。我希望这些消息只传输一次到脚本,无论收件人有多少。
在 /etc/postfix/main.cf 中我有:
default_transport = customsmtp
该传输方法在 /etc/postfix/master.cf 中定义为:
customsmtp unix - n n - - pipe
flags=FR user=cody argv=/var/relay/custom-relay/endpoint.py type:relay env:production sender:${sender} recipient:${recipient}
以下是 Postfix 邮件日志的摘录,显示了对该脚本的多次传送:
Mar 19 20:26:29 ip-172-31-2-6 postfix/cleanup[18639]: 2ACDD24199: message-id=<[email protected]>
Mar 19 20:26:29 ip-172-31-2-6 postfix/qmgr[29229]: 2ACDD24199: from=<[email protected]>, size=2715, nrcpt=2 (queue active)
Mar 19 20:26:30 ip-172-31-2-6 postfix/pipe[18640]: 2ACDD24199: to=<[email protected]>, relay=customsmtp, delay=0.89, delays=0.2/0.01/0/0.67, dsn=2.0.0, status=sent (delivered via customsmtp service)
Mar 19 20:26:30 ip-172-31-2-6 postfix/pipe[18641]: 2ACDD24199: to=<[email protected]>, relay=customsmtp, delay=0.9, delays=0.2/0.04/0/0.66, dsn=2.0.0, status=sent (delivered via customsmtp service)
Mar 19 20:26:30 ip-172-31-2-6 postfix/qmgr[29229]: 2ACDD24199: removed
作为 Postfix 的新手,我不确定需要配置哪些其他设置才能实现此目的。我应该修改哪些其他配置设置,或者我可以提供更多信息来帮助解决此问题?
编辑
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
default_transport = customsmtp
html_directory = no
inet_interfaces = all
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = cody.example.com
myhostname = cody.example.com
myorigin = $mydomain
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
smtpd_helo_required = yes
smtpd_helo_restrictions = reject_invalid_helo_hostname
smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
smtpd_sasl_path = smtpd
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = cyrus
smtpd_tls_CAfile = /etc/path/to/crt.crt
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/path/to/crt2.crt
smtpd_tls_key_file = /etc/path/to/key.key
smtpd_tls_loglevel = 1
smtpd_tls_security_level = encrypt
smtpd_tls_session_cache_database = btree:/var/spool/postfix/smtpd_tls_cache
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
unknown_local_recipient_reject_code = 550
答案1
添加这些参数main.cf
virtual_alias_maps = pcre:/etc/postfix/deduplicate
enable_original_recipient = no
然后在deduplicate
文件中,输入
/.*/ [email protected]
不要忘记执行postfix reload
解释:
参数 enable_original_recipient 将防止在将别名设置为 dummy @gmail.com 时出现重复。设置别名后,postfix 会将电子邮件通过管道传输到海关smtp
警告:
脚本中的参数接收者将被替换为[电子邮件保护]. 因此您将失去原始收件人
答案2
以下配置似乎适合您的目的:
main.cf:(Ubuntu 中除了mydestination
、default_transport
和之外的默认设置local_transport
)
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no
# appending .domain is the MUA's job.
append_dot_mydomain = no
readme_directory = no
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = vagrant-ubuntu-trusty-64
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = vagrant-ubuntu-trusty-64, localhost.localdomain, , localhost, example.org
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all
default_transport=test
local_transport=test
master.cf:
test unix - n n - - pipe
user=nobody argv=/usr/local/bin/test ${sender} ${recipient}
在 /usr/local/bin/测试:
#!/bin/sh
logfile="/tmp/postfix_transport.log"
content=`cat`
date -R >> "$logfile"
echo "$@" >> "$logfile"
使用 发送电子邮件将在以下位置生成消息:sendmail -f [email protected] [email protected] [email protected] < mail
/tmp/postfix_transport.log
Sun, 03 May 2015 19:19:47 +0000
[email protected] [email protected] [email protected]
答案3
https://github.com/ureyni/postfix.3.1可能是你的问题的解决方案