0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【postfix】 postfixがメールを受け取って、「.forward」でスクリプトが実行されるまでの流れ

Last updated at Posted at 2020-09-29

はじめに

ほぼ使わない技術かもしれませんが、レガシーシステムをいじっているときのpostfixの知見を自分用メモとして書きます。

内容

postfixで受信するとかもナンセンスやろとかも、全部置いておいて、以下知見メモです。

[メール受信の設定]

・postfix受信
・/etc/postfix/main.cfで設定されている、「myhostnameパラメータ」により自分のドメインを示して、メールを受信できる状態にします
 → 「mydomainパラメータ」でもドメインを設定しますが、こちらは設定してもしなくても問題ありません
・/etc/postfix/main.cfで設定されている、「inet_interfacesパラメータ」でどこからのメールだけを受け取るか設定します
 → 基本は「all」で設定して全部受け取るようにします
・/etc/postfix/main.cfで設定されている、「inet_protocolsパラメータ」でipv4やipv6のプロトコルを選択します
・「postconf -n」で全体のmain.cfの設定を確認することができます
 → 反映が問題ないかは「postfix check」を使用します

※参考:https://www.rem-system.com/mail-postfix01/

[実行ファイルの設定]

・/etc/postfix/virtualで設定されている、「hogehoge.com anything」ですべてを受け取り、「@hogehoge user@hoge.com」で「hogehoge.com」で受信した内容を「userユーザ」で「hoge.com」に送信する設定をします
 → /etc/postfix/virtualの内容を反映するために、「postmap /etc/postfix/virtual」を実行します
・/etc/postfix/main.cfで設定されている、「home_mailbox = Maildir/」で「/home/user/Maildir/new」にメールが転送される
・/etc/postfix/main.cfで設定されている、「command_directory = /usr/sbin」よりPostfix コマンド群の置かれる場所が分かる
・「/usr/sbin/postconf」内部に「allow_mail_to_commands = alias, forward」がありここら辺の設定で、.forwardが読み込まれる
・.forward内部で設定されているスクリプトが実行される
 → .forwardがないと、「/home/<ユーザ名>/Maildir/new」に内容が記述されていく
・.forwardにかかれている「python hogehoge.py」スクリプトが実行される

※参考:http://www.postfix-jp.info/trans-2.3/jhtml/virtual.5.html
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?