From 05d502558f1a43c0071b72c40eda2a792d6ad75c Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 24 May 2012 11:14:58 +0000 Subject: [PATCH] add a friendly from address to vacation messages; probably needs more work to beautify it though...; change error handling if we cannot send the reply to be hopefully more robust git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1389 a1433add-5e2c-0410-b055-b7f2511e0802 --- VIRTUAL_VACATION/vacation.pl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/VIRTUAL_VACATION/vacation.pl b/VIRTUAL_VACATION/vacation.pl index a53fadc4..5bfcf600 100644 --- a/VIRTUAL_VACATION/vacation.pl +++ b/VIRTUAL_VACATION/vacation.pl @@ -487,6 +487,7 @@ sub send_vacation_email { my $from = $email; my $to = $orig_from; my %smtp_connection; + my $friendly_from = "Vacation Service"; %smtp_connection = ( 'smtp' => $smtp_server, 'port' => $smtp_server_port, @@ -499,12 +500,14 @@ sub send_vacation_email { 'ctype' => 'text/plain; charset=UTF-8', 'headers' => 'Precedence: junk', 'headers' => 'X-Loop: Postfix Admin Virtual Vacation', + 'on_errors' => 'die', # raise exception on error ); my %mail; # I believe Mail::Sender qp encodes the subject, so we no longer need to. %mail = ( 'subject' => $subject, 'from' => $from, + 'fake_from' => $friendly_from . " <$from>", 'to' => $to, 'msg' => encode_base64($body) ); @@ -513,12 +516,17 @@ sub send_vacation_email { $logger->info(%mail); return 0; } - $Mail::Sender::NO_X_MAILER = 1; - my $sender = new Mail::Sender({%smtp_connection}); - $sender->Open({%mail}); - $sender->SendLineEnc($body); - $sender->Close() or $logger->error('Failed to send vacation response: ' . $sender->{'error_msg'}); - $logger->debug("Vacation response sent to $to, from $from"); + eval { + $Mail::Sender::NO_X_MAILER = 1; + my $sender = new Mail::Sender({%smtp_connection}); + $sender->Open({%mail}); + $sender->SendLineEnc($body); + $sender->Close(); + $logger->debug("Vacation response sent to $to, from $from"); + }; + if ($@) { + $logger->error("Failed to send vacation response: $@ / " . $Mail::Sender::Error); + } } }