常見問題集

Postfix

Q: postfix中我如何讓我的配置生效?
Q: postfix中我如何刷新郵件隊列?
Q: 我如何設置postfix的隊列延遲?
Q: 如何禁止postfix對客戶端IP作反向域名解析?
Q: 有什麼工具可以幫忙我分析我的postfix日誌嗎?
Q: 投遞郵件~/Maildir/下出現,example.org/Maildir/
Q: 刪除郵件隊列
Q: 卸載Postfix
Q: NOQUEUE: reject
Q: /var/mail 空間不足
Q: 拒收附件括展名為.exe|.com|.bat|...的郵件
Q:   

Q: postfix中我如何讓我的配置生效?

A: 以root用戶身份 postfix reload,postfix 並沒用restart筆者也不建議你使用restart,reboot,restart這是一個壞習慣

Q: postfix中我如何刷新郵件隊列?

A: 以root用戶身份 postfix flush

Q: 我如何設置postfix的隊列延遲?

A: 你可以在postfix的主要配置檔案/etc/postifx/main.cf中修改下列參數:

queue_run_delay (預設值 1000秒) 設置多長時間隊列管理進程去掃瞄無法投遞的郵件

Maximal_queue_lifetime (預設值 5天) 設置郵件在隊列裡的最長時間

Minimal_backoff_time (預設值 1000秒) 在這個時間內,郵件不能夠被鎖定

Maximal_backoff_time (預設值 4000秒) 在這個時間之後,如果郵件仍然沒有被投遞,就認為是無法投遞

qmgr_message_recipient_limit (預設值 1000) |

Q: 如何禁止postfix對客戶端IP作反向域名解析?

A: 以root用戶身份登錄 postconf -e disable_client_dns_lookup = 1 postfix reload

Q: 有什麼工具可以幫忙我分析我的postfix日誌嗎?

A: James S. Seymour用perl寫了一個叫pflogsumm.pl的腳本,可以到這裡下載:http://jimsun.linxnet.com/postfix_contrib.html,然後可以在crontab中添加下面的內容: 0 2 * * * /path/to/pflogsumm.pl -d today /var/log/maillog | mail -s "Mail Report" you@youdomain.com 定時把分析報告寄給你,其它的一些使用參數可以看pflogsumm.pl裡的信息。

Q: 投遞郵件~/Maildir/下出現,example.org/Maildir/

A: 這個問題是因為出現兩個同名郵件地址

Q: 刪除郵件隊列

A: mailq | tail +2 | awk 'BEGIN { RS = "" } / chen@example\.org$/ { print $1 }' | tr -d '*!' | postsuper -d -

[root@linuxas3 root]# vi mailqueue
#!/bin/bash
# openunix@163.com
queue=$1
# echo ${queue}
DELETE="mailq | tail +2 | awk  'BEGIN { RS = \"\" } /${queue}$/ { print \$1 }' | tr -d '*!' | postsuper -d -"
echo ${DELETE} > queue
chmod 755 queue
./queue
[root@linuxas3 root]# chmod 755 mailqueue
[root@linuxas3 root]# ./mailqueue chen@example\\.org
mailq | tail +2 | awk 'BEGIN { RS = "" } /chen@example\.org$/ { print $1 }' | tr -d '*!' | postsuper -d -
postsuper: 9A427225DEE: removed
postsuper: 97CB6225D8E: removed
postsuper: 980B0225DF0: removed
postsuper: DAF67225D8B: removed
postsuper: A5303225D90: removed
postsuper: 2B285225DED: removed
postsuper: 761EB225D8A: removed
postsuper: 5EC8D225D86: removed
postsuper: C6AE2225DEC: removed
postsuper: 0C35C225DF1: removed
postsuper: E4361225DEA: removed
postsuper: 36717225D8D: removed
postsuper: 30E0D225DEF: removed
postsuper: BD2B2225DF3: removed
postsuper: Deleted: 14 messages
		

Q: 卸載Postfix

A: 複製下面命令粘貼到CLI上即可。

postfix stop
rm -rf /usr/libexec/postfix/bounce
rm -rf /usr/libexec/postfix/cleanup
rm -rf /usr/libexec/postfix/error
rm -rf /usr/libexec/postfix/flush
rm -rf /usr/libexec/postfix/lmtp
rm -rf /usr/libexec/postfix/local
rm -rf /usr/libexec/postfix/master
rm -rf /usr/libexec/postfix/nqmgr
rm -rf /usr/libexec/postfix/pickup
rm -rf /usr/libexec/postfix/pipe
rm -rf /usr/libexec/postfix/proxymap
rm -rf /usr/libexec/postfix/qmgr
rm -rf /usr/libexec/postfix/qmqpd
rm -rf /usr/libexec/postfix/showq
rm -rf /usr/libexec/postfix/smtp
rm -rf /usr/libexec/postfix/smtpd
rm -rf /usr/libexec/postfix/spawn
rm -rf /usr/libexec/postfix/trivial-rewrite
rm -rf /usr/libexec/postfix/virtual
rm -rf /usr/sbin/postalias
rm -rf /usr/sbin/postcat
rm -rf /usr/sbin/postconf
rm -rf /usr/sbin/postfix
rm -rf /usr/sbin/postkick
rm -rf /usr/sbin/postlock
rm -rf /usr/sbin/postlog
rm -rf /usr/sbin/postmap
rm -rf /usr/sbin/postsuper
rm -rf /usr/sbin/postdrop
rm -rf /usr/sbin/postqueue
rm -rf /usr/sbin/sendmail
rm -rf /usr/bin/newaliases
rm -rf /usr/bin/mailq
rm -rf /etc/postfix/LICENSE
rm -rf /etc/postfix/access
rm -rf /etc/postfix/aliases
rm -rf /etc/postfix/canonical
rm -rf /etc/postfix/main.cf
rm -rf /etc/postfix/main.cf.default
rm -rf /etc/postfix/master.cf
rm -rf /etc/postfix/pcre_table
rm -rf /etc/postfix/postfix-files
rm -rf /etc/postfix/regexp_table
rm -rf /etc/postfix/relocated
rm -rf /etc/postfix/transport
rm -rf /etc/postfix/virtual
rm -rf /etc/postfix/postfix-script
rm -rf /etc/postfix/post-install
rm -rf /usr/local/man/man1/mailq.1
rm -rf /usr/local/man/man1/newaliases.1
rm -rf /usr/local/man/man1/postalias.1
rm -rf /usr/local/man/man1/postcat.1
rm -rf /usr/local/man/man1/postconf.1
rm -rf /usr/local/man/man1/postdrop.1
rm -rf /usr/local/man/man1/postfix.1
rm -rf /usr/local/man/man1/postkick.1
rm -rf /usr/local/man/man1/postlock.1
rm -rf /usr/local/man/man1/postlog.1
rm -rf /usr/local/man/man1/postmap.1
rm -rf /usr/local/man/man1/postqueue.1
rm -rf /usr/local/man/man1/postsuper.1
rm -rf /usr/local/man/man1/sendmail.1
rm -rf /usr/local/man/man5/access.5
rm -rf /usr/local/man/man5/aliases.5
rm -rf /usr/local/man/man5/canonical.5
rm -rf /usr/local/man/man5/pcre_table.5
rm -rf /usr/local/man/man5/regexp_table.5
rm -rf /usr/local/man/man5/relocated.5
rm -rf /usr/local/man/man5/transport.5
rm -rf /usr/local/man/man5/virtual.5
rm -rf /usr/local/man/man8/bounce.8
rm -rf /usr/local/man/man8/cleanup.8
rm -rf /usr/local/man/man8/defer.8
rm -rf /usr/local/man/man8/error.8
rm -rf /usr/local/man/man8/flush.8
rm -rf /usr/local/man/man8/lmtp.8
rm -rf /usr/local/man/man8/local.8
rm -rf /usr/local/man/man8/master.8
rm -rf /usr/local/man/man8/nqmgr.8
rm -rf /usr/local/man/man8/pickup.8
rm -rf /usr/local/man/man8/pipe.8
rm -rf /usr/local/man/man8/proxymap.8
rm -rf /usr/local/man/man8/qmgr.8
rm -rf /usr/local/man/man8/qmqpd.8
rm -rf /usr/local/man/man8/showq.8
rm -rf /usr/local/man/man8/smtp.8
rm -rf /usr/local/man/man8/smtpd.8
rm -rf /usr/local/man/man8/spawn.8
rm -rf /usr/local/man/man8/trivial-rewrite.8
rm -rf /usr/local/man/man8/virtual.8
rm -rf /etc/postfix/sample-aliases.cf
rm -rf /etc/postfix/sample-auth.cf
rm -rf /etc/postfix/sample-canonical.cf
rm -rf /etc/postfix/sample-compatibility.cf
rm -rf /etc/postfix/sample-debug.cf
rm -rf /etc/postfix/sample-filter.cf
rm -rf /etc/postfix/sample-flush.cf
rm -rf /etc/postfix/sample-ldap.cf
rm -rf /etc/postfix/sample-lmtp.cf
rm -rf /etc/postfix/sample-local.cf
rm -rf /etc/postfix/sample-mime.cf
rm -rf /etc/postfix/sample-misc.cf
rm -rf /etc/postfix/sample-pcre-access.cf
rm -rf /etc/postfix/sample-pcre-body.cf
rm -rf /etc/postfix/sample-pcre-header.cf
rm -rf /etc/postfix/sample-qmqpd.cf
rm -rf /etc/postfix/sample-rate.cf
rm -rf /etc/postfix/sample-regexp-access.cf
rm -rf /etc/postfix/sample-regexp-body.cf
rm -rf /etc/postfix/sample-regexp-header.cf
rm -rf /etc/postfix/sample-relocated.cf
rm -rf /etc/postfix/sample-resource.cf
rm -rf /etc/postfix/sample-rewrite.cf
rm -rf /etc/postfix/sample-smtp.cf
rm -rf /etc/postfix/sample-smtpd.cf
rm -rf /etc/postfix/sample-transport.cf
rm -rf /etc/postfix/sample-virtual.cf
rm -rf /etc/postfix
rm -rf /usr/libexec/postfix
rm -rf /var/spool/postfix
				

Q: NOQUEUE: reject

Sep 17 23:18:44 localhost postfix/smtpd[12087]: connect from unknown[192.168.0.254]
Sep 17 23:18:44 localhost postfix/smtpd[12087]: NOQUEUE: reject: RCPT from unknown[192.168.0.254]: 550 <test@example.net>: Recipient address rejected: User unknown in local recipient table; from=<test@example.net> to=<test@example.net> proto=ESMTP helo=<netkiller>
Sep 17 23:18:54 localhost postfix/smtpd[12087]: lost connection after RCPT from unknown[192.168.0.254]
Sep 17 23:18:54 localhost postfix/smtpd[12087]: disconnect from unknown[192.168.0.254]
			

A: main.cf中沒有設置local_recipient_maps =

Q: /var/mail 空間不足

A: mount --bind /var/mail/ /home/mail/

[root@linux home]# mkdir -m755 mail
[root@linux home]# mount --bind /var/mail/ /home/mail/
[root@linux home]# ls mail/
axia  chen  crm  cvs  cvsroot  example.net  guest  ming  postfix  root  sales  svnroot  test
[root@linux home]# mount
/dev/hda8 on / type ext3 (rw)
none on /proc type proc (rw)
usbdevfs on /proc/bus/usb type usbdevfs (rw)
/dev/hda1 on /boot type ext3 (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda2 on /home type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/hda7 on /tmp type ext3 (rw)
/dev/hda9 on /u01 type ext3 (rw)
/dev/hda5 on /usr type ext3 (rw)
/dev/hda3 on /var type ext3 (rw)
/var/mail on /home/mail type none (rw,bind)
[root@linux home]# umount /var/mail
[root@linux home]# mount
/dev/hda8 on / type ext3 (rw)
none on /proc type proc (rw)
usbdevfs on /proc/bus/usb type usbdevfs (rw)
/dev/hda1 on /boot type ext3 (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda2 on /home type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/hda7 on /tmp type ext3 (rw)
/dev/hda9 on /u01 type ext3 (rw)
/dev/hda5 on /usr type ext3 (rw)
/dev/hda3 on /var type ext3 (rw)
[root@linux home]#

				

Q: 拒收附件括展名為.exe|.com|.bat|...的郵件

A: 如果你安裝了amavis它可以完成拒收.預設是彈回.如果你不想安裝它,可以使用postfix的mime_header_checks

debian:~# postconf -e 'mime_header_checks=pcre:/etc/postfix/body_checks'
				

創建body_checks檔案內容如下:

debian:~# vi /etc/postfix/body_checks
/^((Content-(Disposition: attachment;|Type:).*|\ +)| *)(file)?name\ *=\ *"?.*\.(lnk|asd|hlp|ocx|reg|bat|c[ho]m|cmd|exe|dll|vxd|pif|scr|hta|jse?|sh[mbs]|vb[esx]|ws[fh]|wmf)"?\ *$/      REJECT  attachment type not allowed
				

reload

debian:~# /etc/init.d/postfix reload
Reloading Postfix configuration...done.
debian:~#
				

Q:   

A: