LoginSignup
4
6

More than 3 years have passed since last update.

Dovecot Sieveメールフィルタリング入門

Last updated at Posted at 2020-03-28

Dovecot Sieve

  • SieveはDovecotと連携するメールフィルタリング用のプログラミング言語
  • Dovecot内部では、Sieveを実装したPigeonholeがプラグインとして含まれている
  • Postfixの仕様でバーチャルドメイン配送( virtual_transport = virtual )では .forward使えないから回避策でsieveを使ったりする

基本の使い方

基本書式はif文を使う

require ["fileinto"]; // オプションコマンド

if address :is "from" "test@example.com" // エンベロープFromが指定のメールアドレスなら
{
    fileinto "testfolder"; 指定のメールボックスに配送
}

オプションコマンド

  • fileinto 指定したメールボックスに配送
  • keep デフォルトのメールボックスに配送
  • discard メール破棄
  • reject メール拒否
  • redirect 指定したメールアドレスにメール転送
  • stop 処理停止

vacation拡張で自動返信機能も実装できる

SPAMメールを拒否する

require ["reject"];

if header :contains "X-Spam-Flag" "YES" // メールヘッダにSPAM判定を付けられているなら
{
    reject "your mail is rejected."; // メール拒否
}

DKIM, YENMAと組み合わせて使うイメージ

複数条件でフィルタリング

AND条件はallof、OR条件はanyof

require ["body", "fileinto", "mailbox"];

if allof {
    header "X-Spam-Flag" "YES", // メールヘッダにSPAM判定を付けられているかつ
    not body :contains "TEST", // メールボディに指定の文字列が含まれていないなら
} {
    fileinto :create "spamfolder"; // 指定のメールフォルダに配送する
}

自動返信(vacation拡張)

require "vacation";

vacation
    :days 1 // 同一送信元には1日1回まで返信
    :subject "auto reply"
    :from "test@example.com"
"this mail is auto reply."

Dovecot LDA(Local Delivery Agent)との組み合わせ

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6