[pve-devel] [PATCH manager v2 1/1] use PVE::Tools::sendmail for update notifications
Stoiko Ivanov
s.ivanov at proxmox.com
Thu Sep 3 14:09:46 CEST 2020
instead of calling /usr/sbin/sendmail directly.
Tested with:
```
echo "[]" > /var/lib/pve-manager/pkgupdates
pvesh create /nodes/rosa/apt/update --notify 1
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
PVE/API2/APT.pm | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index 859c5f42..984c8103 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -344,15 +344,9 @@ __PACKAGE__->register_method({
my $hostname = `hostname -f` || PVE::INotify::nodename();
chomp $hostname;
my $mailfrom = $dcconf->{email_from} || "root";
+ my $subject = "New software packages available ($hostname)";
- my $data = "Content-Type: text/plain;charset=\"UTF8\"\n";
- $data .= "Content-Transfer-Encoding: 8bit\n";
- $data .= "FROM: <$mailfrom>\n";
- $data .= "TO: $mailto\n";
- $data .= "SUBJECT: New software packages available ($hostname)\n";
- $data .= "\n";
-
- $data .= "The following updates are available:\n\n";
+ my $data = "The following updates are available:\n\n";
my $count = 0;
foreach my $p (sort {$a->{Package} cmp $b->{Package} } @$pkglist) {
@@ -365,14 +359,9 @@ __PACKAGE__->register_method({
}
}
- return if !$count;
-
- my $fh = IO::File->new("|sendmail -B 8BITMIME -f $mailfrom $mailto") ||
- die "unable to open 'sendmail' - $!";
-
- print $fh $data;
+ return if !$count;
- $fh->close() || die "unable to close 'sendmail' - $!";
+ PVE::Tools::sendmail($mailto, $subject, $data, undef, $mailfrom, '');
foreach my $pi (@$pkglist) {
$pi->{NotifyStatus} = $pi->{Version};
--
2.20.1
More information about the pve-devel
mailing list