如何用 python 過濾信件內文

雷電MAILD 沒有過濾內文的功能,不是不會開發,而是覺得這功能過於無用,也可能會因用戶的定義關鍵字能力而製造出更多誤判問題。

如果您還是有這類需求,請參考這篇文章,利用 python 來做信件內文過濾,其使用的後果自負。

首先,您要準備以下:

  • 您的雷電MAILD 系統環境可以安裝運行 python3,一般來說要 Windows 10 以上
  • 下載我們製作的信件內文過濾程式,其 zip 包含 email_filter.py 及 keywords.txt

(1) 首先,先建立一個目錄 C:\email_filter,在其下再建立 \logs 及 \mails 兩個子目錄。

(2) 把下載的信件內文過濾程式 zip 解壓縮放到 C:\email_filter

(3) 把關鍵字設到 keywords.txt 裡,一行一組關鍵字

(4) 到雷電MAILD 的事件處理器,啟用他並且建立條件為[全部收到的信件],其執行程式設為您電腦裡的 python.exe 路徑

C:\Python\Python311\python.exe
參數設定為
"C:\email_filter\email_filter.py" "%F" "C:\email_filter\keywords.txt" "C:\email_filter\mails" "C:\email_filter\logs"

過濾到的信件就會移動到 C:\email_filter\mails 目錄

如果想把過濾到的信件移到使用者信箱裡的未經驗證信匣 (-unsolicited-),請改用下列參數,這就不需要記錄檔的產生,因為信件依然在使用者信箱內

"C:\email_filter\email_filter.py" "%F" "C:\email_filter\keywords.txt" "%B\%A\-unsolicited-"

(5) 請寄一封內含關鍵字的信來做測試,也可以用指令列的方式來測試

(6) 參數說明如下:

usage: email_filter.py [-h] eml_path keywords_file target_dir [log_dir]

EML 關鍵字過濾工具 (含 Log 紀錄)

positional arguments:
  eml_path       [必要]要檢查的 .eml 檔案路徑
  keywords_file  [必要]關鍵字設定檔路徑 (txt)
  target_dir     [必要]符合關鍵字時要存放的目標目錄, 例: C:\email_filter\mails
  log_dir        [可選]紀錄檔目錄, 例: C:\email_filter\logs, 檔名格式為 YYYYMMDD.log, 不給參數即不產生紀錄檔			
			

 

 

感謝您看完此篇文章

回知識庫首頁

最近更新日期: 2025/11/27

Copyright © RaidenMAILD TEAM

Copyright (C) http://www.raidenmaild.com/ . , all rights reserved. The copyrighted works contained in this information service shall not be copied, reproduced, varied, altered, modified, adapted, distributed, performed and displayed in any form without the written permission of the copyright owner. All trademarks belong to their respective owners .