[pmg-devel] [PATCH pmg-api v2 3/6] smtp-engine: use admin-mail-from as from header for bounces

Stoiko Ivanov s.ivanov at proxmox.com
Tue Feb 25 16:01:59 CET 2025


generate_ndr is currently only used to generate a bounce-mail if the
following occur:
* email is blocked only for part of the receivers
* before-queue-filtering is active - in the after-queue case postfix
  generates the bounces for us.

With this patch the header of the bounce message will contain
'Proxmox Mail Gateway <postmaster>' (or the setting of
admin-mail-from) instead of 'postmaster', but this should not affect
deliverability of these mails.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/SMTP.pm | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/PMG/SMTP.pm b/src/PMG/SMTP.pm
index b7bc5d3..15c8464 100644
--- a/src/PMG/SMTP.pm
+++ b/src/PMG/SMTP.pm
@@ -185,7 +185,8 @@ sub loop {
 			$self->reply ("250 2.5.0 OK ($queueid)");
 			if ($cfg->get('mail', 'ndr_on_block')) {
 			    my $dnsinfo = $cfg->get_host_dns_info();
-			    generate_ndr($self->{from}, [ @reject_rec ], $dnsinfo->{fqdn}, $queueid) if scalar(@reject_rec);
+			    my $from_header = $cfg->get('admin', 'admin-mail-from');
+			    generate_ndr($self->{from}, [ @reject_rec ], $dnsinfo->{fqdn}, $queueid, $from_header) if scalar(@reject_rec);
 			}
 		    } else {
 			$self->reply ("451 4.4.0 detected undelivered mail ($queueid)");
@@ -265,7 +266,7 @@ sub save_data {
 }
 
 sub generate_ndr {
-    my ($sender, $receivers, $hostname, $queueid) = @_;
+    my ($sender, $receivers, $hostname, $queueid, $from_header) = @_;
 
     my $ndr_text = <<EOF
 This is the mail system at host $hostname.
@@ -284,7 +285,7 @@ EOF
     my $ndr = MIME::Entity->build(
 	Type => 'multipart/report; report-type=delivery-status;',
 	To => $sender,
-	From => 'postmaster',
+	From => $from_header,
 	Subject => 'Undelivered Mail');
 
     $ndr->attach(
-- 
2.39.5





More information about the pmg-devel mailing list