Ricerca nel sito web

Come configurare i messaggi di rimbalzo Postfix personalizzati


Su questa pagina

  1. 1 versione Postfix
  2. 2 Imposta maximal_queue_lifetime e delay_warning_time
  3. 3 Crea un messaggio di mancato recapito personalizzato
  4. 4 collegamenti

A partire dalla versione 2.3 di Postfix, Postfix supporta i messaggi di rimbalzo personalizzati. Questa guida mostra come configurare i messaggi di rimbalzo Postfix personalizzati e la durata massima della coda.

1 versione Postfix

Per prima cosa dovresti scoprire la tua versione di Postfix per assicurarti che supporti i messaggi di rimbalzo personalizzati:

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

Se il tuo Postfix è 2.3 o più recente, allora sei a posto.

2 Impostare maximal_queue_lifetime e delay_warning_time

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

maximal_queue_lifetime: il tempo massimo in cui un messaggio viene messo in coda prima di essere rispedito come non recapitabile.

delay_warning_time: il tempo dopo il quale il mittente riceve le intestazioni dei messaggi di posta ancora in coda.

Il comando postconf -n mostra le impostazioni attualmente configurate in /etc/postfix/main.cf, mentre il comando postconf -d mostra le impostazioni predefinite che sono valide a meno che non sia impostato qualcos'altro in /etc/postfix/main.cf.

Per scoprire il valore corrente di maximal_queue_lifetime, puoi eseguire

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

Se postconf -n non visualizza nulla, significa che il valore di postconf -d è attualmente in uso:

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

Lo stesso vale per 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:~#

Se vuoi modificare queste impostazioni, puoi usare il comando postconf -e. Scriverà le impostazioni in /etc/postfix/main.cf, ad es. come questo:

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

Riavvia Postfix in seguito:

service postfix restart

Il motivo per cui ci preoccupiamo di queste due impostazioni è che i loro valori possono essere utilizzati nei messaggi di rimbalzo personalizzati.

3 Crea un messaggio di mancato recapito personalizzato

Da http://www.postfix.org/bounce.5.html:

Il file modello può specificare i modelli per la posta non riuscita, la posta ritardata, la consegna riuscita o per la verifica dell'indirizzo. Questi modelli sono denominati rispettivamente modello_fallimento, modello_ritardo, modello_successo e modello_verifica. Puoi, ma non devi, specificare tutti e quattro i modelli in un file modello di rimbalzo.

Ogni modello inizia con \template_name=<

Ora possiamo creare il file /etc/postfix/bounce.cf che contiene i modelli in questo modo (sto usando tutti e quattro i modelli qui, ma puoi tralasciare quelli che non ti servono). È assolutamente importante che il file termini con una riga vuota!

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

Puoi personalizzare i messaggi a tuo piacimento. Nei messaggi è possibile utilizzare tutte le variabili main.cf (ad es. $myhostname). Se dai un'occhiata a delay_template, vedrai che utilizzo le variabili aggiuntive $delay_warning_time_hours e $maximal_queue_lifetime_days. Potresti anche usare $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, ma tieni presente ciò che http://www.postfix.org/bounce.5.html spiega su queste variabili:

delay_warning_time_suffix: si espande nel valore del parametro delay_warning_time, espresso nell'unità di tempo specificata da un suffisso, che è uno tra secondi, minuti, ore, giorni o settimane.

maximal_queue_lifetime_suffix: si espande nel valore del parametro maximal_queue_lifetime, espresso nell'unità di tempo specificata da suffisso. Vedi sopra in delay_warning_time per i possibili valori di suffisso.

Quindi, se usi la variabile $delay_warning_time_minutes invece di $delay_warning_time_hours nel tuo template, dovresti farla seguire dalla parola \minutes\ invece di \hours\.

Successivamente, configuriamo Postfix per utilizzare i modelli personalizzati:

postconf -e 'bounce_template_file = /etc/postfix/bounce.cf'

Per controllare come appaiono i modelli quando tutte le variabili vengono sostituite con i loro valori reali e per assicurarti che non ci siano errori nei tuoi modelli (ad esempio una nuova riga mancante alla fine di /etc/postfix/bounce.cf), esegui:

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:~#

Se non vengono mostrati errori, possiamo riavviare Postfix in modo che possa utilizzare i modelli personalizzati:

service postfix restart

4 collegamenti

  • Pagina man di Postfix bounce: http://www.postfix.org/bounce.5.html
  • Parametri di configurazione di Postfix: http://www.postfix.org/postconf.5.html