dshimizu/blog

アルファ版

Postfixでバウンスメールのコピーを特定のユーザ宛てに送付する

Postfixでバウンスメールのコピーをエラーとして指定したユーザ(デフォルトはPostmaster)へ送付したいときの設定メモ。

バウンスメールとは

バウンスメールとはwikipediaによると以下のものを指す。

  • バウンスメール - Wikipedia
  • バウンスメール (bounce message) とは、電子メールの仕組みにおいて、送信したメールメッセージが何等かの理由で目的の送信先に正常に配信されなかった場合に、メールサーバからその旨を送信元に通知されるメールメッセージのこと。
    

メールアカウントのユーザ設定をきちんと行っていれば、送信したメールが何らかの形でエラーになった場合のバウンスメールは、送信したメールアカウント宛てに返されるので何もしなくても特に問題ない...はず。

しかしそれ以外のユーザ宛てのメッセージや、不正に発生したエラーを一通り取っておきたいとかのケースもあるのでそんなときのためにどこをいじれば良いかのメモ。

環境

試した環境は以下のもの。

設定内容

main.cfに以下をパラメータを設定する。 notify_classesは postmaster@ 宛に報告されるエラーのリスト。以下の設定はエラー系のものをすべて通知するようにしているが、バウンスのみ受信したい場合は bounce を追記するだけで良い。 ただし、外部に公開されていてリレーを禁止しているようなメールサーバでこのあたりの設定をすると、スパム等の不正なSMTP接続がdouble bounceとなって、半端ない数のメールを受信することになる可能性があるので要注意。特にprotocolの指定があると中途半端に接続されてすぐ切られたときにもメールが来て結構ツライ。

notify_classes = bounce, delay, policy, protocol, resource, software

この状態で、相手にメールが送れなかった場合にその内容が postmaster 宛てに通知される。 バウンスの通知先を postmaster@ から変えたい場合はbounce_notice_recipientや2bounce_notice_recipientのパラメータを変更する(デフォルトがpostmaster )。

  • Postfix Configuration Parameters
  • 2bounce_notice_recipient (default: postmaster)
        The recipient of undeliverable mail that cannot be returned to the sender. This feature is enabled with the notify_classes parameter.
    
    bounce_notice_recipient (default: postmaster)
        The recipient of postmaster notifications with the message headers of mail that Postfix did not deliver and of SMTP conversation transcripts of mail that Postfix did not receive. This feature is enabled with the notify_classes parameter.
    
    また、バウンス関連のその他の設定項目としては下記がある。
    bounce_queue_lifetime (default: 5d)
        Consider a bounce message as undeliverable, when delivery fails with a temporary error, and the time in the queue has reached the bounce_queue_lifetime limit. By default, this limit is the same as for regular mail.
        Time units: s (seconds), m (minutes), h (hours), d (days), w (weeks). The default time unit is d (days).
        Specify 0 when mail delivery should be tried only once.
        This feature is available in Postfix 2.1 and later.
    
    bounce_service_name (default: bounce)
        The name of the bounce(8) service. This service maintains a record of failed delivery attempts and generates non-delivery notifications.
        This feature is available in Postfix 2.0 and later.
    
    bounce_size_limit (default: 50000)
        The maximal amount of original message text that is sent in a non-delivery notification. Specify a byte count. A message is returned as either message/rfc822 (the complete original) or as text/rfc822-headers (the headers only). With Postfix version 2.4 and earlier, a message is always returned as message/rfc822 and is truncated when it exceeds the size limit.
    
        Notes:
            If you increase this limit, then you should increase the mime_nesting_limit value proportionally.
            Be careful when making changes. Excessively large values will result in the loss of non-delivery notifications, when a bounce message size exceeds a local or remote MTA's message size limit.
    

設定したら postfix の reload を忘れずに。

$ sudo systemctl reload postfix

まとめ

Postfixでバウンスメール、およびその他エラーメールの通知・受信の設定方法について書いた。 とりあえず何かあったときのためにエラー系のメールを受信して残しておきたいならpostmaster 宛てメールを保存できるようにしておけばよい。

参考