我正在试图通过Postfix将电子邮件传递给我的Python脚本。 目前,具有多个收件人的邮件将通过pipe道传送给每个收件人一次。 无论收件人的数量多less,我都希望这些邮件只能传递给脚本一次。
在/etc/postfix/main.cf我有:
default_transport = customsmtp
那个传输方法在/etc/postfix/master.cf中定义为:
customsmtp unix - nn - - 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我不知道还有什么其他的设置需要configuration,以实现这一点。 我应该修改哪些其他configuration设置,或者是否有更多信息可以帮助解决这个问题?
编辑
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
在main.cf
添加这些参数
virtual_alias_maps = pcre:/etc/postfix/deduplicate enable_original_recipient = no
然后在deduplicate
文件中放入
/.*/ [email protected]
不要忘记执行postfix reload
说明:
参数enable_original_recipient将防止重复到别名@ gmail.com的别名。 别名后,后缀将pipe道电子邮件到customsmtp
警告:
您脚本中的参数收件人将被replace为[email protected]。 所以你会失去原来的收件人
以下configuration似乎适用于您的目的:
main.cf :(除了mydestination
, default_transport
和local_transport
之外,在Ubuntu下是默认的)
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 - nn - - pipe user=nobody argv=/usr/local/bin/test ${sender} ${recipient}
在/ usr / local / bin目录/testing:
#!/bin/sh logfile="/tmp/postfix_transport.log" content=`cat` date -R >> "$logfile" echo "$@" >> "$logfile"
使用sendmail -f [email protected] [email protected] [email protected] < mail
发送电子邮件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]