사용자 정의 접미사 반송 메시지를 구성하는 방법

사용자 정의 접미사 반송 메시지를 구성하는 방법

2022-10-17 last update

12 minutes reading postfix
Postfix 버전 2.3부터 Postfix는 사용자 지정 반송 메시지를 지원합니다. 이 가이드는 사용자 정의 Postfix 반송 메시지 및 최대 대기열 수명을 설정하는 방법을 보여줍니다.

1 접미사 버전

First you should find out about your Postfix version to make sure it supports custom bounce messages:

postconf -d | grep mail_version
server2:~# postconf -d | grep mail_version
mail_version = 3.4.13
milter_macro_v = $mail_name $mail_version
server2:~#

If your Postfix is 2.3 or newer, then you're good to go.

2 maximal_queue_lifetime 및 delay_warning_time 설정

From http://www.postfix.org/postconf.5.html:

maximal_queue_lifetime: The maximal time a message is queued before it is sent back as undeliverable.

delay_warning_time: The time after which the sender receives the message headers of mail that is still queued.

(adsbygoogle=window.adsbygoogle||[]).push({});

The postconf -n command shows the settings that are currently configured in /etc/postfix/main.cf, whereas the postconf -d command shows the default settings that are valid unless something else is set in /etc/postfix/main.cf.

To find out about the current value of maximal_queue_lifetime, you can run

postconf -d | grep maximal_queue_lifetime
postconf -n | grep maximal_queue_lifetime

If postconf -n doesn't display anything, this means the value from postconf -d is currently being used:

server2:~# postconf -d | grep maximal_queue_lifetime
maximal_queue_lifetime = 5d
server2:~# postconf -n | grep maximal_queue_lifetime
server2:~#

The same goes for delay_warning_time:

postconf -d | grep delay_warning_time
postconf -n | grep delay_warning_time
server2:~# postconf -d | grep delay_warning_time
delay_warning_time = 0h
server2:~# postconf -n | grep delay_warning_time
server2:~#

If you want to modify these settings, you can use the postconf -e command. It will write the settings to /etc/postfix/main.cf, e.g. like this:

postconf -e 'maximal_queue_lifetime = 1d'
postconf -e 'delay_warning_time = 0h'

Restart Postfix afterwards:

service postfix restart

The reason that we care about these two settings is that their values can be used in the custom bounce messages.

3 사용자 지정 반송 메시지 만들기

From http://www.postfix.org/bounce.5.html :
템플릿 파일은 실패한 메일, 지연된 메일, 성공적인 배달 또는 주소 확인을 위한 템플릿을 지정할 수 있습니다. 이러한 템플릿의 이름은 각각 failure_template, delay_template, success_template 및 verify_template입니다. 바운스 템플릿 파일에서 네 가지 템플릿을 모두 지정할 수는 있지만 반드시 그런 것은 아닙니다.
각 템플릿은 "template_name = <이제 다음과 같은 템플릿이 포함된/etc/postfix/bounce.cf 파일을 만들 수 있습니다(여기서 4개의 템플릿을 모두 사용하고 있지만 필요하지 않은 템플릿은 생략할 수 있습니다). 파일이 빈 줄로 끝나는 것이 절대적으로 중요합니다!

nano /etc/postfix/bounce.cf
#
# The failure template is used when mail is returned to the sender;
# either the destination rejected the message, or the destination
# could not be reached before the message expired in the queue.
#

failure_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
Postmaster-Subject: Postmaster Copy: Undelivered Mail

This is the mail system at host $myhostname.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system
EOF


#
# The delay template is used when mail is delayed. Note a neat trick:
# the default template displays the delay_warning_time value as hours
# by appending the _hours suffix to the parameter name; it displays
# the maximal_queue_lifetime value as days by appending the _days
# suffix.
#
# Other suffixes are: _seconds, _minutes, _weeks. There are no other
# main.cf parameters that have this special behavior.
#
# You need to adjust these suffixes (and the surrounding text) if
# you have very different settings for these time parameters.
#

delay_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Delayed Mail (still being retried)
Postmaster-Subject: Postmaster Warning: Delayed Mail

This is the mail system at host $myhostname.

####################################################################
# THIS IS A WARNING ONLY.  YOU DO NOT NEED TO RESEND YOUR MESSAGE. #
####################################################################

Your message could not be delivered for more than $delay_warning_time_hours hour(s).
It will be retried until it is $maximal_queue_lifetime_days day(s) old.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system
EOF


#
# The success template is used when mail is delivered to mailbox,
# when an alias or list is expanded, or when mail is delivered to a
# system that does not announce DSN support. It is an error to specify
# a Postmaster-Subject: here.
#

success_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Successful Mail Delivery Report

This is the mail system at host $myhostname.

Your message was successfully delivered to the destination(s)
listed below. If the message was delivered to mailbox you will
receive no further notifications. Otherwise you may still receive
notifications of mail delivery errors from other systems.

                   The mail system
EOF


#
# The verify template is used for address verification (sendmail -bv
# address...). or for verbose mail delivery (sendmail -v address...).
# It is an error to specify a Postmaster-Subject: here.
#

verify_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Mail Delivery Status Report

This is the mail system at host $myhostname.

Enclosed is the mail delivery report that you requested.

                   The mail system
EOF

You can customize the messages to your liking. In the messages, you can use all main.cf variables (e.g. $myhostname). If you take a look at the delay_template, you'll see that I use the additional variables $delay_warning_time_hours and $maximal_queue_lifetime_days. You could as well use $delay_warning_time_seconds, $delay_warning_time_minutes, $delay_warning_time_days, $delay_warning_time_weekes resp. $maximal_queue_lifetime_seconds, $maximal_queue_lifetime_minutes, $maximal_queue_lifetime_hours, $maximal_queue_lifetime_weeks, but keep in mind what http://www.postfix.org/bounce.5.html explains about these variables:

delay_warning_time_suffix: Expands into the value of the delay_warning_time parameter, expressed in the time unit specified by a suffix, which is one of seconds, minutes, hours, days, or weeks.

maximal_queue_lifetime_suffix: Expands into the value of the maximal_queue_lifetime parameter, expressed in the time unit specified by suffix. See above under delay_warning_time for possible suffix values.

So if you use the variable $delay_warning_time_minutes instead of $delay_warning_time_hours in your template, you should follow it by the word "minutes" instead of "hours".

Next, we configure Postfix to use the custom templates:

postconf -e 'bounce_template_file = /etc/postfix/bounce.cf'
모든 변수가 실제 값으로 대체될 때 템플릿이 어떻게 보이는지 확인하고 템플릿에 오류가 없는지 확인하려면(예:/etc/postfix/bounce.cf 끝에 줄 바꿈 누락) 다음을 실행하십시오.
postconf -b /etc/postfix/bounce.cf
server2:~# postconf -b /etc/postfix/bounce.cf
expanded_failure_text = <<EOF
This is the mail system at host server2.example.com.

I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system
EOF

expanded_delay_text = <<EOF
This is the mail system at host server2.example.com.

####################################################################
# THIS IS A WARNING ONLY.  YOU DO NOT NEED TO RESEND YOUR MESSAGE. #
####################################################################

Your message could not be delivered for more than 0 hour(s).
It will be retried until it is 1 day(s) old.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the attached returned message.

                   The mail system
EOF

expanded_success_text = <<EOF
This is the mail system at host server2.example.com.

Your message was successfully delivered to the destination(s)
listed below. If the message was delivered to mailbox you will
receive no further notifications. Otherwise you may still receive
notifications of mail delivery errors from other systems.

                   The mail system
EOF

expanded_verify_text = <<EOF
This is the mail system at host server2.example.com.

Enclosed is the mail delivery report that you requested.

                   The mail system
EOF
server2:~#

If no errors are shown, we can restart Postfix so that it can use the custom templates:

service postfix restart

4 링크


  • 접미사 바운스 매뉴얼 페이지: http://www.postfix.org/bounce.5.html
  • 접미사 구성 매개변수: http://www.postfix.org/postconf.5.html