From 972ef4048240d2ff196fe4559bee21e4052fe01f Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 27 Feb 2020 18:32:32 +0100 Subject: [PATCH] Rewrite util_send_status_mail to go through the SMTP server So emails get signed by qpsmtpd --- root/var/lib/zabbix/bin/util_send_status_mail | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/root/var/lib/zabbix/bin/util_send_status_mail b/root/var/lib/zabbix/bin/util_send_status_mail index 47653e1..57481a5 100644 --- a/root/var/lib/zabbix/bin/util_send_status_mail +++ b/root/var/lib/zabbix/bin/util_send_status_mail @@ -1,23 +1,31 @@ #!/usr/bin/perl -w -use Mail::Send; use esmith::ConfigDB; +use MIME::Lite; +use Net::SMTP; -my $c = esmith::ConfigDB->open_ro(); +my $c = esmith::ConfigDB->open_ro(); my $domain = $c->get('DomainName')->value(); -my $host = $c->get('SystemName')->value(); -my $z = $c->get('zabbix-agent'); -my $dest = $z->prop('StatusRecipient') || 'admin@' . $domain; +my $host = $c->get('SystemName')->value(); +my $z = $c->get('zabbix-agent'); +my $dest = $z->prop('StatusRecipient') || 'admin@' . $domain; -my $mail = new Mail::Send; -$mail->to("$dest"); -$mail->set("From","zabbix-agent"); -$mail->subject("[STATUS] $host.$domain"); -my $body = $mail->open; -print $body localtime(time)."\n", - "\n#>tail /var/log/messages :\n", - `/usr/bin/tail \$(readlink /var/log/messages)`, - "\n#>netstat --numeric-hosts -tpu :\n", - `/bin/netstat --numeric-hosts -tpu`; -$body->close; +my $smtp = Net::SMTP->new('localhost'); +my $mail = MIME::Lite->new( + From => 'smeserver-status@' . $domain, + To => $dest, + Subject => "[STATUS] $host.$domain", + Data => localtime(time)."\n" . + "\n#>tail /var/log/messages :\n" . + `/usr/bin/tail \$(readlink /var/log/messages)` . + "\n#>netstat --numeric-hosts -tpu :\n" . + `/bin/netstat --numeric-hosts -tpu` +); + +$smtp->mail('smeserver-status@' . $domain); +$smtp->recipient($dest); +$smtp->data(); +$smtp->datasend($mail->as_string); +$smtp->dataend(); +$smtp->quit;