原文:http://blog.xuite.net/tolarku/blog/58439089-Postfix+Mail+Queue+-+%E4%B8%80%E4%BA%9B%E7%B0%A1%E5%96%AE%E7%9A%84%E7%AE%A1%E7%90%86%E6%8C%87%E4%BB%A4

 

在 UNIX 的寄信程式不論是  Sendmail 或是 Postfix 都有處理「當信件無法即時寄出」的方法,簡單的來說就是 Mail Queue (郵件佇列),底下就簡單的來說說一些指令,怎麼來觀看並處理 Mail Queue.

※ 查看卡在 mail queue 的信件 
mailq
postqueue -p

※ Mail Queue 所在的目錄 
/var/spool/mqueue
/var/spool/postfix -- 底下列出 postfix 的子目錄

》active
目前正在準備發送的信件。(在 message id 後會多加一個 * 號)
Messages  that  the  queue  manager  has opened for delivery. Only a  limited  number  of  messages  is allowed  to  enter  the  active queue (leaky bucket strategy, for a fixed delivery rate).

》bounce
每一位收件者的傳送狀態,並記載為何會被退信
Per-recipient status information about why mail  is bounced.    These   files  are  maintained  by  the bounce(8) daemon.

》corrupt
信件損毀導致無法傳送的信件
Unreadable  or  damaged  queue files are moved here for inspection.

》defer
暫時無法被傳送的信件,並記載為何會被延遲傳送。這種情形最常發生在你的 Mail Server 被列入灰名單(GrayList)的時候,你會看到訊息為「 Your access to this mail system has been rejected due to the sending MTA's poor reputation. If you believe that this failure is in error, please contact the intended recipient via alternate means.」
Per-recipient status information about why mail  is delayed. These files are maintained by the defer(8) daemon.

》deferred
無法被傳送的信件會放置在此目錄,但 Mail Server 還是會嘗試幫你繼續送,只是必須等 Backoff time。
Mail that could not be  delivered  upon  the  first attempt.  The  queue manager implements exponential backoff  by  doubling  the  time  between  delivery attempts.

》hold
被暫時停止發送的信件,如要發送出去,需要由手動(在 message id 後會多加一個 ! 號)
Messages that are kept  "on  hold"  are  kept  here until someone sets them free.

》incoming
從外部或本地寄送到本機的信件。
Inbound mail from the network, or mail picked up by the local pickup(8) daemon from the maildrop directory.

※ 刪除所有在 Mail Queue 中所有的信件 ※※※

rm /var/spool/mqueue
postsuper -d ALL
不建議這麼做,除非你真的清楚知道你不要所有的信件!

※ 刪除所有在 deferred 狀態的信件 ※※※

因為 /var/spool/postfix/deferred 目錄下尚有 0~F 的子目錄,所以不好用 rm 一次將他清空,故系統有提供指令方式幫助你清理 deferred 下的信件

1. postsuper -d ALL deferred
後面帶的 deferred 是 queue_id ,所以你也可以用這個方法來清除其他的 queue
2. find /var/spool/postfix/deferred -type f -exec rm -vf \{\} \;
這個方法是用 find 找出該目錄下所有的檔案,找到後丟給後面的 rm 去做刪除的動作。

3. find /var/spool/postfix/deferred/  -type f -exec mv -vf \{\} /backup/mqueue/deferred/ \;
小弟建議用這個方法!這方法同第二種,只不過他不直接殺,而是將 deferred 的信件搬移到你指定的目錄去,例如例子中的 /backup/mqueue/deferred/,萬一有啥問題還可以救回來。(註:最後的 \; 不能省略唷!)

※ 刪除過了 5天仍被放在 deferred 還是寄不出去的信件 ※※
1.  find /var/spool/postfix/deferred -type f -mtime +5 -exec rm -f \{\} \;
2.  find /var/spool/postfix/deferred -type f -mtime +5 -exec mv -vf \{\} /backup/mqueue/deferred/ \;

※ 刪除來自於 xxx@123.com 的信件 ※※
通常我們都會開放「認證」的使用者在單位以外的地方,透過 mail server 發送信件,但萬一某個使用者帳號被盜用後,這個方便將是非常大的傷害,你會發現你的 mail queue 裡怎麼會有那麼多,不是自己 domain e-mail 所發出的信件。

刪除特定 e-mail 寄送的信件
mailq | grep "xxx@123.com" | cut -d " " -f1 | cut -d’*’ -f1 | postsuper -d -
--------------------------------------------------------------------------------------
mailq 列出 queue
grep 找特定人事
cut -d" " -f1 取出第一個欄位 message_id
cut -d"*" -f1 去掉星號 * (因為若該訊息是在 active queue 會多個 *)
postsuper -d - 刪除前面所取出來的  message_id

刪除特定文字的訊息

/usr/sbin/postqueue -p | grep "MAILER-DAEMON" | cut -d " " -f1 | cut -d"*" -f1 | /usr/sbin/postsuper -d -
-------------------------------------------------------------------------------------

※ qmgr 是postfix 處理 mail queue 的 daemon ※※
說明請看 http://www.postfix.org/qmgr.8.html
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 migasun 的頭像
    migasun

    GOOGLE來的

    migasun 發表在 痞客邦 留言(0) 人氣()