Postfix:将所有传入的电子邮件重定向到脚本

时间:2013-12-27 07:14:26

标签: email postfix-mta

我需要设置一个后缀服务器来接收电子邮件并将电子邮件正文发布到bbs。

Postfix版本:2.10.2

/etc/postfix/main.cf文件:

queue_directory = /var/spool/postfix
command_directory = /usr/bin
daemon_directory = /usr/lib/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mail.mydummydomain.com
mydomain = mydummydomain.com
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
local_recipient_maps =
virtual_alias_maps = hash:/etc/postfix/redirect
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8, 192.168.56.0/24, 192.168.79.0/24
alias_maps = hash:/etc/postfix/aliases
alias_database = $alias_maps
debug_peer_level = 2
debugger_command =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/bin/sendmail
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /etc/postfix/sample
readme_directory = /usr/share/doc/postfix

(我必须添加“local_recipient_maps =”否则电子邮件将被拒绝,“550 5.1.1< ...>:收件人地址被拒绝:本地收件人表中的用户未知”。)

/等/后缀/重定向:

/*/ tomyscript

/等/后缀/别名:

MAILER-DAEMON:  postmaster
postmaster:     root
bin:            root
daemon:         root
named:          root
nobody:         root
uucp:           root
www:            root
ftp-bugs:       root
postfix:        root
manager:        root
dumper:         root
operator:       root
abuse:          postmaster
tomyscript:     "|/tmp/myscript.py >> /tmp/mail.log"
decode:         root

当我向我的postfix服务器发送测试邮件时,显然它没有重定向到我的脚本:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.mydummydomain.com ESMTP Postfix
ehlo mydummydomain.com
250-mail.mydummydomain.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<aaa@mydummydomain.com>
250 2.1.0 Ok
rcpt to:<bbb@mydummydomain.com>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
this is the email body
.
250 2.0.0 Ok: queued as 825061A003D

后缀日志:

Dec 27 15:04:28 Arch postfix/smtpd[2812]: connect from localhost.localdomain[127.0.0.1]
Dec 27 15:06:26 Arch postfix/smtpd[2812]: 825061A003D: client=localhost.localdomain[127.0.0.1]
Dec 27 15:06:35 Arch postfix/cleanup[2814]: 825061A003D: message-id=<20131227070626.825061A003D@mail.mydummydomain.com>
Dec 27 15:06:35 Arch postfix/qmgr[2804]: 825061A003D: from=<aaa@mydummydomain.com>, size=368, nrcpt=1 (queue active)
Dec 27 15:06:35 Arch postfix/local[2815]: 825061A003D: to=<bbb@mydummydomain.com>, relay=local, delay=110, delays=110/0.01/0/0.03, dsn=5.1.1, status=bounced (unknown user: "bbb")
Dec 27 15:06:35 Arch postfix/cleanup[2814]: 7BA861A0041: message-id=<20131227070635.7BA861A0041@mail.mydummydomain.com>
Dec 27 15:06:35 Arch postfix/bounce[2816]: 825061A003D: sender non-delivery notification: 7BA861A0041
Dec 27 15:06:35 Arch postfix/qmgr[2804]: 7BA861A0041: from=<>, size=2209, nrcpt=1 (queue active)
Dec 27 15:06:35 Arch postfix/qmgr[2804]: 825061A003D: removed
Dec 27 15:06:35 Arch postfix/local[2815]: 7BA861A0041: to=<aaa@mydummydomain.com>, relay=local, delay=0.02, delays=0.01/0/0/0.01, dsn=5.1.1, status=bounced (unknown user: "aaa")
Dec 27 15:06:35 Arch postfix/qmgr[2804]: 7BA861A0041: removed
Dec 27 15:06:57 Arch postfix/smtpd[2812]: disconnect from localhost.localdomain[127.0.0.1]

myscript.py:

#!/usr/bin/env python2

import sys

for line in sys.stdin.read().split('\n'):
    print line

有什么想法吗?

0 个答案:

没有答案