all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v2 1/1] use PVE::Tools::sendmail for update notifications
Date: Thu,  3 Sep 2020 14:09:46 +0200	[thread overview]
Message-ID: <20200903120946.23596-4-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20200903120946.23596-1-s.ivanov@proxmox.com>

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@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





  parent reply	other threads:[~2020-09-03 12:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-03 12:09 [pve-devel] [PATCH common/manager v2] adapt PVE::Tools::sendmail to match rust-implementation and use it for apt " Stoiko Ivanov
2020-09-03 12:09 ` [pve-devel] [PATCH common v2 1/2] sendmail-helper: only send multipart if necessary Stoiko Ivanov
2020-09-03 12:09 ` [pve-devel] [PATCH common v2 2/2] sendmail helper: allow empty display name in from Stoiko Ivanov
2020-09-03 12:09 ` Stoiko Ivanov [this message]
2020-09-07  8:06 ` [pve-devel] applied-series: [PATCH common/manager v2] adapt PVE::Tools::sendmail to match rust-implementation and use it for apt update notifications Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200903120946.23596-4-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal