From patchwork Fri Feb 7 12:25:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Fleischer X-Patchwork-Id: 1492 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id CBD0616E8B1B3 for ; Fri, 7 Feb 2020 12:25:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1, MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_NONE=-0.0001,SPF_HELO_NONE=0.001, T_DMARC_POLICY_NONE=0.01 autolearn=ham autolearn_force=no version=3.4.3 X-Spam-BL-Results: [127.0.9.0] [127.0.0.11] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Fri, 7 Feb 2020 12:25:17 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 356DC18B76B9AB; Fri, 7 Feb 2020 12:25:08 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 8DAD718B76B9A5; Fri, 7 Feb 2020 12:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581078307; bh=/WDZMR4lkBfM51sKahwU0fvSAXVRa3ATvWJCr+ZJ3zM=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=NzuEtWx1+sRiVFKCyg+xDCehsdY2u1rkaHnLgpj9YSweVEw6bImVcsvIrelPyoRQS LZVOtn4jdG3208Vic/l4PjepBf6XVmQxkEg9ZSFy/brKbE5Z+TN/6/rzr6PspdKT1Z 0iQ3CGjj9C3IQdRAd0QZALYe7LFDuUICPyG/kvXeP6eNdswWv6YVq1rj+seiNSjS7b C6KQz/FJXqd3wiEjH7awH/CmwOf11xJzjmFXsX1cpRtA3Owb/WR8P9srHtq6KRd3+C egC48TFqQTAV34OebP7g/wOREari9IitpuxnatyDpkEfSR5iSXHFif3zG8320nNk4W uoir6wKFC8+wdyBlMa53UAXzOpoK+vtfR0o7rs8LLjpYAp89aY1ioKuoqNs8uB9gVu mYM/2BQT0dswGgO7bPTJmB1pzjh5NYxobzvAs1cvm7km6AmQEYbP0esxJNWJm3WyIM GAN0OXm8bQI/sOB1A8JM2OY5KnFF6WJlUvYFOqrd8KBGxKaX+PeXLIFb5BpJ5bk+nF ULzWNSufN2dcxONP78/3b/irYQaw/PeIZy6zQUKajJwGivchPnEA3g3Ds2kf5WY5PU uiNREAIJjhkjVeLmuRy7yEEHYKH8CoXBKLSRbeqwUySCi+Nk2gbhT2L7ac7OUv0Lyn jgC0/rsb0BZWTLcM+OqAByQo= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 7D8B82BFE6; Fri, 7 Feb 2020 12:25:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1581078307; bh=/WDZMR4lkBfM51sKahwU0fvSAXVRa3ATvWJCr+ZJ3zM=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=mI2qPk3Lt5nrzt3kASmibiiBe1OOTH/FmphAGP6l0tfjGoRVQbyUFZGdIyhxKNAgK vizR6rMfSHo2yZ0/98lMpVdEOZV/VytGpCb+6nj+/8YJ9j7sXmstY9lojTea//pq+l HI6O5BRNBXmwX+2BQWvcSTi/DHNzqF7YQvJ0MmSdIpMStOfMGHWGgIoTw2aVNgWgw4 UQsiOb6Pn72xDktzKPBTDm0KjCbbWzbwT3rbP8FMmMnlOI6VvarqJIrw6oU/BtPl6D 7Kgygms7H/9zrG0floHXZ+HqA8a5I3kGWPFjWg8czbcKKhUNu4FVcb/7E8aGN6op7c 6ktuAzWe5QS5pRcyYryxaVoYEmAPn9j/W68qCwiMc18q4ZdqJh+Suv56CkmLXV0ws3 H6FUmuisPt4hY/qgNzr3AiXnUTYG8UGp2iQMCWivUL2ZKNIKYLXLBH4ca8sZ0Qgfnp YVki87ga6FKKc8pRTuEr4o/XWiro5Kye0eQlZXpsnUdzv00yVvDap+ev5TLBHCRgOM PtAFvcYdi8jPervb4ey1YexTBMZwo1XAEwXs3ZPlI4VC2EfCitXJVjJR3FYffjMZ08 LW4hlrsvLmqJi6DTd4XJC6umFu5icWb0YO0+0BjB8RcnMxHgS7DNEYWoaS9ez2Xx9+ 7qTOsAH+CWt2PmaWchM1q1vY= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 899D92BFE4 for ; Fri, 7 Feb 2020 12:25:02 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 7 Feb 2020 12:25:02 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 2260B18B76B99C for ; Fri, 7 Feb 2020 12:24:57 +0000 (UTC) Received: from localhost (HSI-KBW-091-089-090-042.hsi2.kabelbw.de [91.89.90.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: lfleischer) by orion.archlinux.org (Postfix) with ESMTPSA id EF66918B76B99B for ; Fri, 7 Feb 2020 12:24:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581078297; bh=/WDZMR4lkBfM51sKahwU0fvSAXVRa3ATvWJCr+ZJ3zM=; h=From:To:Subject:Date; b=Fw+WpuwvIB2dqzHUOMGKP4v9rjlta4vzg3trZzZ8Wxnd9rrk+TS3bqso7c2mAfqb8 2zjZQn2Kp+EYOwh4qb+ddxa4j6VZAbwbPRuoFvgjFuAWqEQuOtZNHsC4DFdTl/Xxyy uBsgLRK7SOTyPURyRA2FaFd5xlUyfzYfaByfNHFbemSvDnEQLn20KASeDg9ZQNf6gl GTysGvvFYr+DbVJ3CumRvIaBAf0bPysDO2O7TSBL+BgaVBEUpdsD6JF/6FNHngUTYs LK4441NDT2qoV6L0ZwUmaANbI3EsHLcXifCXt3isMlGh2VD6e9iwIv2DZ6/slo3Esl xp+VB47p0b0xSEuMmm2dwU0qsbTmvn++YnnPl3VtFijLmoJ0jPcDx7DniH138vvBG4 ux+1DlQvVas2f+WTfUTFy+uKsw6b3vN6IZ7R4L0mXTzR6ZD/1dDw8XtE5Ij3q6Bqp5 GqZkg/Ney2rcTfb8PEOybA06+fT427OR84UR8rZReDSJJA2/wnK28bZp9m86/PA140 D1nO2FTMOswoMG7wVTuEFPvCJkawxK11FPZOceM55YKdlETEKkMnPIfCC7nnoUgb7U uWF0gh2YQ1YV2GCCsOI99Y9UWzjdLuYdbslRYpoj7EanNv4+78AeuAL9XeK9cbARp6 L6avZiXp51uigQI0/BF2fbtk= From: Lukas Fleischer To: aur-dev@archlinux.org Subject: [PATCH] Use smtplib for sending emails Date: Fri, 7 Feb 2020 13:25:07 +0100 Message-Id: <20200207122507.81550-1-lfleischer@archlinux.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-BeenThere: aur-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Arch User Repository \(AUR\) Development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: aur-dev-bounces@archlinux.org Sender: "aur-dev" Support mail delivery without a local MTA. Instead, an SMTP server can now be configured using the smtp-server option in the [notifications] section. Signed-off-by: Lukas Fleischer --- aurweb/scripts/notify.py | 13 ++++++++----- conf/config.defaults | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py index b0f218b..35d2701 100755 --- a/aurweb/scripts/notify.py +++ b/aurweb/scripts/notify.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 import email.mime.text -import subprocess +import email.utils +import smtplib import sys import textwrap @@ -63,7 +64,7 @@ class Notification: return body.rstrip() def send(self): - sendmail = aurweb.config.get('notifications', 'sendmail') + server_addr = aurweb.config.get('notifications', 'smtp-server') sender = aurweb.config.get('notifications', 'sender') reply_to = aurweb.config.get('notifications', 'reply-to') reason = self.__class__.__name__ @@ -79,13 +80,15 @@ class Notification: msg['Reply-to'] = reply_to msg['To'] = to msg['X-AUR-Reason'] = reason + msg['Date'] = email.utils.formatdate(localtime=True) for key, value in self.get_headers().items(): msg[key] = value - p = subprocess.Popen([sendmail, '-t', '-oi'], - stdin=subprocess.PIPE) - p.communicate(msg.as_bytes()) + server = smtplib.SMTP(server_addr) + server.set_debuglevel(1) + server.sendmail(sender, recipient, msg.as_bytes()) + server.quit() class ResetKeyNotification(Notification): diff --git a/conf/config.defaults b/conf/config.defaults index c519eae..af85ce8 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -47,7 +47,7 @@ window_length = 86400 [notifications] notify-cmd = /usr/local/bin/aurweb-notify -sendmail = /usr/bin/sendmail +smtp-server = orion.archlinux.org sender = notify@aur.archlinux.org reply-to = noreply@aur.archlinux.org