- 论坛徽章:
- 0
|
想做一个统计列表文件,其中记录所有邮件的发送者和接收者,利用postfix的内容过滤功能
我的记录脚本:- vim /usr/src/sms/script
- #!/bin/sh
- INSPECT_DIR=/usr/src/sms
- SENDMAIL="/usr/sbin/sendmail -G -i"
- EX_TEMPFAIL=75
- EX_UNAVAILABLE=69
- trap "rm -f in.$" 0 1 2 3 15
- cd $INSPECT_DIR||{
- echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }
-
- cat >in.$||{
- echo Cannot save mail to file; exit $EX_TEMPFAIL; }
-
- $SENDMAIL "$@" <in.$
- exit $?
复制代码 在/etc/postfix/master.cf添加- smtp inet n - n - - smtpd
- -o content_filter=filter:
- filter unix - n n - - pipe
- flags=Rq user=vmail argv=/usr/src/sms/script -f ${sender} -- ${recipient}
-
复制代码 如果将以上两句去掉,即不进行内容过滤时,此邮件系统工作正常。
当用domain1的域名邮箱向此domail2中发送一封邮件时,/var/log/maillog日志如下(只是其中一段)- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: connect from domain1.com[192.168.0.20]
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: 3DC501376D8: client=domain1.com[192.168.0.20]
- Jun 13 16:57:38 domain2 postfix/cleanup[3120]: 3DC501376D8: message-id=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: disconnect from domain1.com[192.168.0.20]
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 3DC501376D8: from=<user1@domain1.com>, size=1579, nrcpt=1 (queue active)
- Jun 13 16:57:38 domain2 sendmail[3127]: o5D8vc2X003127: Authentication-Warning: localhost.localdomain: vmail set sender to user1@domain1.com using -f
- Jun 13 16:57:38 domain2 sendmail[3127]: o5D8vc2X003127: from=user1@domain1.com, size=1581, class=0, nrcpts=1, msgid=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>, relay=vmail@localhost
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: connect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: 450F51376DD: client=localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/cleanup[3120]: 450F51376DD: message-id=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 450F51376DD: from=<user1@domain1.com>, size=2025, nrcpt=1 (queue active)
- Jun 13 16:57:38 domain2 sendmail[3127]: o5D8vc2X003127: to=user2@domain2.com , ctladdr=user1@domain1.com (1001/1001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=31581, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 450F51376DD)
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: disconnect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/pipe[3122]: 3DC501376D8: to=<user2@domain2.com >, relay=filter, delay=0.09, delays=0.01/0/0/0.07, dsn=2.0.0, status=sent (delivered via filter service)
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 3DC501376D8: removed
- Jun 13 16:57:38 domain2 sendmail[3131]: o5D8vc7e003131: Authentication-Warning: localhost.localdomain: vmail set sender to user1@domain1.com using -f
- Jun 13 16:57:38 domain2 sendmail[3131]: o5D8vc7e003131: from=user1@domain1.com, size=2020, class=0, nrcpts=1, msgid=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>, relay=vmail@localhost
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: connect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: 534281376D8: client=localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/cleanup[3120]: 534281376D8: message-id=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>
- Jun 13 16:57:38 domain2 sendmail[3131]: o5D8vc7e003131: to=user2@domain2.com , ctladdr=user1@domain1.com (1001/1001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=32020, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 534281376D8)
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 534281376D8: from=<user1@domain1.com>, size=2471, nrcpt=1 (queue active)
- Jun 13 16:57:38 domain2 sendmail[3135]: o5D8vcrn003135: Authentication-Warning: localhost.localdomain: vmail set sender to user1@domain1.com using -f
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: disconnect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/pipe[3128]: 450F51376DD: to=<user2@domain2.com >, relay=filter, delay=0.12, delays=0.04/0/0/0.07, dsn=2.0.0, status=sent (delivered via filter service)
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 450F51376DD: removed
- Jun 13 16:57:38 domain2 sendmail[3135]: o5D8vcrn003135: from=user1@domain1.com, size=2459, class=0, nrcpts=1, msgid=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>, relay=vmail@localhost
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: connect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: 6288A1376DD: client=localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/cleanup[3120]: 6288A1376DD: message-id=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 6288A1376DD: from=<user1@domain1.com>, size=2917, nrcpt=1 (queue active)
- Jun 13 16:57:38 domain2 sendmail[3135]: o5D8vcrn003135: to=user2@domain2.com , ctladdr=user1@domain1.com (1001/1001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=32459, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 6288A1376DD)
- Jun 13 16:57:38 domain2 sendmail[3139]: o5D8vcOq003139: Authentication-Warning: localhost.localdomain: vmail set sender to user1@domain1.com using -f
- Jun 13 16:57:38 domain2 sendmail[3139]: o5D8vcOq003139: from=user1@domain1.com, size=2898, class=0, nrcpts=1, msgid=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>, relay=vmail@localhost
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: disconnect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/pipe[3122]: 534281376D8: to=<user2@domain2.com >, relay=filter, delay=0.13, delays=0.04/0/0/0.09, dsn=2.0.0, status=sent (delivered via filter service)
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 534281376D8: removed
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: connect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: 739841376D8: client=localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/cleanup[3120]: 739841376D8: message-id=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>
- Jun 13 16:57:38 domain2 sendmail[3139]: o5D8vcOq003139: to=user2@domain2.com , ctladdr=user1@domain1.com (1001/1001), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=32898, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 739841376D8)
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 739841376D8: from=<user1@domain1.com>, size=3363, nrcpt=1 (queue active)
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: disconnect from localhost.localdomain[127.0.0.1]
- Jun 13 16:57:38 domain2 postfix/pipe[3128]: 6288A1376DD: to=<user2@domain2.com >, relay=filter, delay=0.12, delays=0.04/0/0/0.08, dsn=2.0.0, status=sent (delivered via filter service)
- Jun 13 16:57:38 domain2 postfix/qmgr[3105]: 6288A1376DD: removed
- Jun 13 16:57:38 domain2 sendmail[3143]: o5D8vcNn003143: Authentication-Warning: localhost.localdomain: vmail set sender to user1@domain1.com using -f
- Jun 13 16:57:38 domain2 sendmail[3143]: o5D8vcNn003143: from=user1@domain1.com, size=3337, class=0, nrcpts=1, msgid=<52768.192.168.0.194.1276419012.squirrel@mail.domain1.com>, relay=vmail@localhost
- Jun 13 16:57:38 domain2 postfix/smtpd[3114]: connect from localhost.localdomain[127.0.0.1]
复制代码 并且postqueue队列中总有一个排队邮件,如下:- [root@localhost sms]# postqueue -p
- -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
- 98CDE1376DD* 2616687 Sun Jun 13 17:08:13 MAILER-DAEMON@localhost.localdomain
- MAILER-DAEMON@localhost.localdomain
- -- 2556 Kbytes in 1 Request.
复制代码 在domail1上面还会受到退信:- This is the mail system at host mail.domain2.com.
- I'm sorry to have to inform you that your message could not
- be delivered to one or more recipients. It's attached below.
- For further assistance, please send mail to <postmaster>
- If you do so, please include this problem report. You can
- delete your own text from the attached returned message.
- The mail system
- <user2@domain2.com>: service unavailable
- Reporting-MTA: dns; mail.domain2.com
- X-Postfix-Queue-ID: CF6FA1376D8
- X-Postfix-Sender: rfc822; user1@domain1.com
- Arrival-Date: Sun, 13 Jun 2010 16:57:38 +0800 (CST)
- Final-Recipient: rfc822; user2@domain2.com
- Original-Recipient: rfc822;user2@domain2.com
- Action: failed
- Status: 5.3.0
- Diagnostic-Code: x-unix; service unavailable
- ------------------------------------------------------------
- From: user1@domain1.com
- To: user2@domain2.com
- Subject: 444
- Date: Sun13 Jun 2010 16:50:12 +0800 (CST)
- 4444
- ------------------------------------------------------------
复制代码 请各位帮忙分析分析,我已经研究了好几天了,头都快炸了,可还是没有成功,多谢了 |
|