From patchwork Fri Feb 7 13:09:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Fleischer X-Patchwork-Id: 1495 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 0421B16E8D4C0 for ; Fri, 7 Feb 2020 13:09:15 +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 13:09:15 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id D2C0D18B782C2D; Fri, 7 Feb 2020 13:09:07 +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 C577D18B782C23; Fri, 7 Feb 2020 13:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581080945; bh=ipfvOqDmXpBnboAxLk5N2Q92AcWCskdMGEbAXIk9Fyk=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=lUPtDZ+/GLSPagSKhBsdhaQrmC7dLcEyJwOxCQQdeMShRlqj22TGLrN3NjFQBCZF8 stdo3C8sn/tjQXXnpfYnaS+nbHK+u65R8cVr0UP+INQPNtlVPpS6BxOLhJtT6qjqqn 7aFUqIAzjd2isVctbpAhNg5Ysi9YazScwWiQsCp4RB8FDsWyZAo5E7V1yZGOIGUxFP cfyx1mQtMDN2i8ZoZAKQpVUZGqrOeS0tKRGwzpiQRffF8pf/4MSIce6iQDXRwjOwML 9kNEf0AJuRrMUT0xiLw/MkXMg7LnBD7FS0EUJ4aU1xrB7dzrBRcVEa50pmdehZTr56 FDzuCEfdBmrg27zkHKuVmTX6OJFVcksyckJguKYjQeNmByUTQEjqhZVwhhkVFmT6Lj i7PD7p+xyVrMseXTsJjp26Md/x8QgMB62TO0uT3a3JGvLCAYJdpK+CGtWMoEvmmrG3 +/aBQpSdoxM5oy/9mvOVwYxXH9RIBb0CkIiemmjU+ohekkfCcLMnjlmwuS6QUKfgO2 4bAHlF3sINjsSNuvgBiF27yARiF48BRPIp1PY1kGTXY8bSMcO1syRcsMuz+tlatSnO 8xMEEDNBxK+4hZg4qPk29Zszd/YgKbAm4EAss0RtXk07TVXtjq7LY/ldjacQeAgy2b YbJ7aNN3JfIWVghszdwTQr/8= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id A27152BFE5; Fri, 7 Feb 2020 13:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1581080945; bh=ipfvOqDmXpBnboAxLk5N2Q92AcWCskdMGEbAXIk9Fyk=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=vRLRHNV3Wzp+BzvSwBd+I+XRyxiJKFE5Oal21J//AYW6j5f+3UuJ8aKOSHHQOfk/Z 9+CQNsioM/6ZAhDnU1L3MnaCJTKG0TK1/VybdQX9cY1TccENw7DCY4BG6fpOevvMls ort6PeSiU8LpIy2bk6pqJtiSFGhdwLzohce7QoV/kkdcd1cSynQeGpf2JboWCTmnY+ yQwIbefUkX03X+r2feiowjvdwSMcF0F0EXPrwWaHvuRffFyuh+LdBCwf9pTSPF3st/ ixGFyHPq83PNdhfwkHr5flqxrZeLvtBAyKE2KpqEQz5UiQIhMTQzy3Cq67ghy0VK3b LpAtKGjELP+U/u84EkAMcCRKGvsYtlmlqHr3JoYXsd6NnSI+/zyVSxNgeRBaLbs0L6 yAxlCw15KHatl2Ev2vSh59OpJyufWhPwzN6Alk3pSqxgehqAaMXvsSeXoINNiYT+xj uG3KhSyiUZBCPUfJ8PNOu/QVfjgnINZ/dc6ma2upSxRELNrP9VaU52MMJbo4QAkvjI dZ78y8dwa6iJ3Xj91LtBZd3hn4E0Rhl92nrvmVveltCMhorxzDC6Dl3LCkxC2K9YRU ngVQc8OtZ8YCL/79z7dRakMhWpqEqnIS27dp2NlwZS7IrYmFH8yYCiX6JMTRYVQ2vI 67ydiZa0T/rGY2ISfUfc3+Ag= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 2DA942BFE4 for ; Fri, 7 Feb 2020 13:09:03 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 7 Feb 2020 13:09:03 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id BAE1E18B782BFC for ; Fri, 7 Feb 2020 13:08:58 +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 890B118B782BFB for ; Fri, 7 Feb 2020 13:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581080938; bh=ipfvOqDmXpBnboAxLk5N2Q92AcWCskdMGEbAXIk9Fyk=; h=From:To:Subject:Date; b=N6a4xtp0Q5BoBf8Iz3I/ZCyRrXBpEZOhA+Leq3GQZBYhHI2Gaom93p2rb6Ng/Z1Y3 ag7BL/ITJWRfPnv87u8DF4Dk/J6jJZCHPRxmi+iLR9gR5IvNzjiozq3McYJDhhmrRH IMwe4cgOGiDyxgQBV7FZgEOI90nhwvxSNFp8Ln30yt5tKchyHavKP2XrSujlq/mcfU I5CIjzyo7ve9ZIt5OEVWt1IJwskAuLWjLGE8Oo/ykw1WRWd0qzfYMzCmJWVSksGFIw 2HxQgNHtljITumijBQ6xKa9TYhnUyF36bXx+Mmr0cNiz4DDw2IMSdtQjr/x7+GQQv0 AGpXiYlKicXDD0SLqYsSs2UOvB7/2bmJ7MemuMKxiPd2+KI0qZfVVZzb6mnQtys3V2 f+XpR8MHHq45SBFhHZ/2SZDpOiVhJQtdvrtRN+s3UZ8tJEsdUXoLYY5KCJx68TcW1N RS6L91FHtBcnOK9psFGPy5uG22CnzMKWLOL0yd+kpoLxLZd/cEEu6OMEuTFNgVR9cQ PCnP8varrsv9QVDmScpUPaomx90MiGUzl4Hvt/y5lTtpR2GiOApn7QM+DfYhOLanj5 GSaER2+X+oaAZ75E/e093gDkEuFtZm1F1UoPrcSyWEfycMrIhmRBn8iDerGm1zpdYV Yu/cft6k/mGX5wQY0JoRBLv0= From: Lukas Fleischer To: aur-dev@archlinux.org Subject: [PATCH v2 1/2] Use smtplib for sending emails Date: Fri, 7 Feb 2020 14:09:13 +0100 Message-Id: <20200207130914.86034-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 --- Change the default configuration to use localhost. 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..e77ccf4 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 = localhost sender = notify@aur.archlinux.org reply-to = noreply@aur.archlinux.org From patchwork Fri Feb 7 13:09:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Fleischer X-Patchwork-Id: 1494 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 24F8F16E8D499 for ; Fri, 7 Feb 2020 13:09:05 +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.0.11] [127.0.9.0] 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 13:09:05 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 0A41418B782C0A; Fri, 7 Feb 2020 13:09:03 +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 844E318B782C04; Fri, 7 Feb 2020 13:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581080943; bh=MnIJB7tVvPdlIQTvslDtxl/xKLKx34vfmqg4q4GqeB4=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=vNP3wZJZ+16DWgcPIorZKSOeH5F0p6uJNboVV15DK9pvsQ+egpLW8FKTKKTrXwf0q K4kppZjdrOYyBzLWW+4Qr4/nW70OyjlCIH+Ulo9/Dq5H49EEsYNwXG8Fda+7kV2rSD VgTv7Cd6Kls4/DfT0NOsOGNm5tuVfPgKTz9SZ45HaL8pFm4MgPu4oMJZ27JjvAUVAM jMyZLuo6qGmf5lTmstrHlgOd7qWudoqc9kuBY7JKsbV3/uYKgAi0IRS3duwCoAl1Cq hRskRpJrNXF5pkyUGz80tWJSjJB0VXGX7RyOmJSj5Nrg5qAvPh3fvMifI8nBPbMULu 6Ks0uRBv5bVlZOSvMc9U6Z4FlRnvre23HgKAwKhQSAQbq7R1UsQ7uZi42KmCuTisAE ggZTDdMG0J+vRZnXt1zz1oQTfB7PqiYkMa7jK4V4KXKHnLILloM4+pQB80hk8rfLLK bKjZpsFyhMBqwhPtyV89ESz5WaJ/IdtPo/bMETshEsVno6DndL22wkAHf2FuyLexoY v2x6GkTPlUfHwOVPRytxTq92NMZHl/+zJ10h2MMJZwb1Eh77WucKATmy9JBtBevwpQ cmdf8yZFep61QTvYxZMn/3eHU2r4Cs/AREvyiA9an7G1Y132dtbotoqOy7PrWqCZkR Tzm4sIp7P+J1zC2gjfIS2Geg= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 6D7B62BFE6; Fri, 7 Feb 2020 13:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1581080943; bh=MnIJB7tVvPdlIQTvslDtxl/xKLKx34vfmqg4q4GqeB4=; h=From:To:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=lAbfcgvp75kvTbe79OFpvWd4xOWyVv3GoCfskHbEJ8KLmA8tqyK/Y3sPybUTm9Tj2 voiH9S7Mpc7GVqMRObniuVI4C1BQX3LtjD+uewfzfVG1s7oPJZGnaMZxgdJzbHPtVy HS6ynuy1u6PgEN/iPOpnZPG/RZ7kigF8SIXgWhwYR5je2qnHNgc58VTtdhcloh9Aa7 qDQ5VE9ctlPKciP1jwaGdxKnQBzblUkGff2qalH4liwlwA/ws1j1HF2KYGFiMwk6We jXl9UuBMgEMKElBQoYzTkq4uzRdL+bd6F2P2oW9T/DeHWwtk+WLm93T7oj7Y/3TLPV wX4KY+NdTu8di6eOoajvhopVuvZUXsNv5tI7pQwGAUxPCHsyUgJVW/eiQQxsKlWfDK y5yhAcLyFuFMe1bJE3f1RtvfnMJmtSaBkwqlrNOf/LgzrWIx8OoitJw5qwRJQ9XtYG dAp2hX/7EuxZzZePczY9ZncJgWEvslmQ6RR6IgbMc8k1VpX4om+FOfXcPq1vKdvm1c NgqeSf+YcA6W+BQJDuWqGd2f9l5cz3oeJ604MUgE6DusSFuJfKfwGdfnfyBGO3TypO UZP63a7KXIMjaW099SXrb+GY+4z6w3EPcblPphkx/1HS+xrW/zvlZBHCNerbnBe9eg fQFpLbYbiSzQnOU5o7EalVWY= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 8B72A2BFE5 for ; Fri, 7 Feb 2020 13:09:00 +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 13:09:00 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 7283F18B782BFE for ; Fri, 7 Feb 2020 13:08:59 +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 3D9CF18B782BFD for ; Fri, 7 Feb 2020 13:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581080939; bh=MnIJB7tVvPdlIQTvslDtxl/xKLKx34vfmqg4q4GqeB4=; h=From:To:Subject:Date:In-Reply-To:References; b=fqc/Iz+pJubEESFlnY8LV5YQz3zjk5gjVw4huHAAstnLWh4NrqhamCimUaBQerGri 5PCN5unQIfz2V49jmGPSsXOriGhv0mURXiDmTB3c+wdiWZzvUaFdZNuqIh2PS0dNgO hqGoOwSNqLMCwcaqy7+eZihIzeop14ek1Z//a/makUnWpBcAheW6R3dwfisnGkhF6r lE9vk6igcfw6Tgaeom15o+DqosMY8EECNoVgy8xgh5ZWMFzzt+Up84X1SPjygR+5uU O6rS1qC2pBfvetj5BoNg+yOmjRU2x/eUiGqFapfqpUIGAdI8L3nWzWyJvYTHetsoHp SPv+2h3gMYJMpyoexOGs84HoNgAqaMp172lGG/csGiCwmTrx3dRjzDxDIroRuVyanX FK5Qe7V20QnqbReut2OjAf0XrYqYP+mbtL76mz8UHF7xfovaDUWaSfWd4YUeK6Jsjx tF5bhmaQUaa0yzRtknnMpHVECKDUOhOJOlaV5pSfkEQtdUw+SUdOHuq2V8P08O84kF IW6NwHZfCvYAgPfrz3rNtl6eeKu1WJL6QAcleJZc7Lxx2og7Qd9wesC9ENLtkf7+M3 H18CGC27oqKrCDvOIJKxMFB3cRSa9eTNcg9fRLOx0gKDaFMDa9UHY2NZbxqly/XE3s 5TWV9LGf6Ya6wJ5m0PbMdCK4= From: Lukas Fleischer To: aur-dev@archlinux.org Subject: [PATCH v2 2/2] Make SMTP port and authentication configurable Date: Fri, 7 Feb 2020 14:09:14 +0100 Message-Id: <20200207130914.86034-2-lfleischer@archlinux.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200207130914.86034-1-lfleischer@archlinux.org> References: <20200207130914.86034-1-lfleischer@archlinux.org> 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" Signed-off-by: Lukas Fleischer --- Change the default configuration to use localhost. aurweb/scripts/notify.py | 19 ++++++++++++++++++- conf/config.defaults | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py index 35d2701..ddf4736 100755 --- a/aurweb/scripts/notify.py +++ b/aurweb/scripts/notify.py @@ -65,6 +65,11 @@ class Notification: def send(self): server_addr = aurweb.config.get('notifications', 'smtp-server') + server_port = aurweb.config.getint('notifications', 'smtp-port') + use_ssl = aurweb.config.getboolean('notifications', 'smtp-use-ssl') + use_starttls = aurweb.config.getboolean('notifications', 'smtp-use-starttls') + smtp_user = aurweb.config.get('notifications', 'smtp-user') + smtp_passwd = aurweb.config.get('notifications', 'smtp-password') sender = aurweb.config.get('notifications', 'sender') reply_to = aurweb.config.get('notifications', 'reply-to') reason = self.__class__.__name__ @@ -85,7 +90,19 @@ class Notification: for key, value in self.get_headers().items(): msg[key] = value - server = smtplib.SMTP(server_addr) + if use_ssl: + server = smtplib.SMTP_SSL(server_addr, server_port) + else: + server = smtplib.SMTP(server_addr, server_port) + + if use_starttls: + server.ehlo() + server.starttls() + server.ehlo() + + if user and password: + server.login(user, passwd) + server.set_debuglevel(1) server.sendmail(sender, recipient, msg.as_bytes()) server.quit() diff --git a/conf/config.defaults b/conf/config.defaults index e77ccf4..40cad04 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -48,6 +48,11 @@ window_length = 86400 [notifications] notify-cmd = /usr/local/bin/aurweb-notify smtp-server = localhost +smtp-port = 25 +smtp-use-ssl = 0 +smtp-use-starttls = 0 +smtp-user = +smtp-password = sender = notify@aur.archlinux.org reply-to = noreply@aur.archlinux.org