From patchwork Mon Feb 10 19:53:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Fleischer X-Patchwork-Id: 1504 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 C91CB16F97E32 for ; Mon, 10 Feb 2020 19:53:11 +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.8 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_LOW=-0.7,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.1] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Mon, 10 Feb 2020 19:53:11 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 6AD0F18CF1CAD3; Mon, 10 Feb 2020 19:53:02 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (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 7A6D818CF1CAC8; Mon, 10 Feb 2020 19:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581364380; bh=8k6xvDDOsKmhC7ISB08kQpkXExcI6cW5TasAMv3pEPk=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=ptpfUnIOCP1whfRZEgIJGdiYMuQFWr1WuBirbp9Mi/eBD3QDPJ3j0loZ/5nGT7+s8 rXdVSTJxAd/mw5+m3gPLJj6vNgsyGg9Y9XcNRB6dypbdOhNDsjhxRjKpyV7jAStTnK Ke1u1Q+8C/ZnWv/yuFy50EbS4zhpuHMP6W0B88M8fBZvgSiBBuH+QxbbJP2Nk7kORX Fg2QC8Uq2P60vaTZztOoaYsNkA4se1gHPzztG/a3SbKYSJ0+/ka498BmzTFXxxmwiO QuLEIsCM515B6iLTKaFM4pqbAtEznIHuhrFZyWqzgewiAb+F3f/IFX1K2vGRd7tOhD xqWOPJ59wkjj8+QPNwxfPuqbTuen8PWz7zC83xLDaLbDdOfcdbm7x/8bsF/Ze5KMgh oF1Dj/i4j51nKLJO1el+KDb7NlJyv3p/bGw2an3hzYzrJkIhhqK4boAqj7KtnExPcI K/B97VjBlOMBjumaIYUToJ8BAx3Z1LZGwQQVZY2iast+fu1jfIE5toM9K1EPIJSUJZ I3trGaj94V/Otu5hjQeSpnlft6LV4D93wc6PvQmbjW1ArWA/EIp/aAls2AcaYM/W0t ld/dbMCNW5Z24sZEnXcRk/Bi2D7nL6ylbYL4Zh4B6UFyvj+IdpZZ0LxSANuDFxxiAv teYa1eYwMWdYVhjP1xAL2Cb8= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 0BACD2BFE3; Mon, 10 Feb 2020 19:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1581364380; bh=8k6xvDDOsKmhC7ISB08kQpkXExcI6cW5TasAMv3pEPk=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=Wj3vHAyUskbA42zewP9F7zAQkj5FakbavF5zE+5Z+QZ9QxOujJqtJP8WJ7CC5cvFC sZdlZmUE1vw5a+6Bb40y+VEvhgNwyQQAVxeicbssRCOqdgB9CgyEknT1HmbrOEGtwZ e4JirC06ICJ/9bhB2LUIOiwcvT9+WonkvWNzj+s7Gi55axKYUiU7t105qWBpLWgADH jrWblAuXfOLaP9W4yPFxMrrzPrzUfBA9J7fuRh21H4m5fFUJyEF1ickwd4ZMpq0ooH pDAZpGXIpFdcliKJLmVio4uEsmIdMKqCt6i+5SeBgJgQS5d/hlbceRzCtbQ/tlHirY Ua8f3L2WHQZHqiFu4wWwl1MYTnx6g6FBccjDlB03apsqqkRbbreohNB00i5Vp6Q2rn oqQIk/gRfaWCMIgMSxanp9l9QcITjhF2l9S6UPORqEg+12RUOeaTJDGzez5MN+wKTJ LT0l+SFFypGf6jSX++WhQ1RfuHE7H6GtKW0Fwt+5hgc3FSIndZvAQsyKN99uOeAT7W te9u9eXU2izTmroS8stZrrIUMwpKfFH2Mj+mvV5TOz5cbUAVdEvcZogRbjdL9yGQHa SPq1ZfwGpfU0VlFu0FQPeske5Dn6BM/qaMoMAu2C7cmZ7U0IMHp4bkiAKhl2Wg97DD uh+eEPbvCPI7ZViLYT8sp5e8= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 6E7422BFE2 for ; Mon, 10 Feb 2020 19:52:57 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Mon, 10 Feb 2020 19:52:57 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id CCD2A18CF1CA9E for ; Mon, 10 Feb 2020 19:52:51 +0000 (UTC) Received: from localhost (unknown [IPv6:2a02:8070:24e4:b800:b66b:fcff:fe3e:6273]) (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 A726D18CF1CA9D for ; Mon, 10 Feb 2020 19:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581364371; bh=8k6xvDDOsKmhC7ISB08kQpkXExcI6cW5TasAMv3pEPk=; h=From:To:Subject:Date; b=D4KKE0AQwunp6y6N9EZmF8m0I508EBuUBE1FDs7opBqYVrVMDPT0UJB1oSX/9qMS3 3FIltC/PlOsBJAnUYm8HKlH0j/KZSe8fzIO7297KlZo1UNEqFvJL4kOz09bjhbLKBa oU/bMOxMSoZF7RCNtXYdvzCoxxcHm3MgkHdobPuJESIcQOqoQGnfKmb06WS8+Y1o4B GhdhiVw+904HEGYWsoLUZtZGAjOE48K5AJ1r3Kki8jYSl0IN7r0FxV9B65YJbuM8pb 0yv+x3aSbsUv6tnlVV/xlvpsbvsl+DMode1qAtMK2CWda9zb+B3MwHQVjnOFjc4jgv 4djoMUsrptHHwiz3ZbMTeevUE9xS00muEAFLfcim5r7u2tAQBjCyxNcMEWtU7iMQv7 UfvlxOpxkDPH+eO9y3OIryxi17Z3/u3+3OXTxWzUV+AtZvhNX3GBfvZSz2WsyVNsYx ZSsLDQEMqDCi0EfSk5Sf+FNLqj6C37mheADP+3ow+JudRRVVfG80Czdy6XeykOL8I2 T1Uu3FwOJbmNoTIoEWCsEAgli5EbSqNasacdYEsjFQnCDn4g0IHB6PO9o6mb/cASC0 8WkSEGj0GZUjNex7kj5bcGcCRvxOx0DTdJMUd69KQl16IEby66/534o1j33s3Lphd3 Yl2j/xNaYOjf7pBoSgIP9YzM= From: Lukas Fleischer To: aur-dev@archlinux.org Subject: [PATCH v4 1/2] Support smtplib for sending emails Date: Mon, 10 Feb 2020 20:53:09 +0100 Message-Id: <20200210195310.145150-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. In order to use this option, the value of the sendmail option must be empty. Signed-off-by: Lukas Fleischer --- aurweb/scripts/notify.py | 22 ++++++++++++++++++---- conf/config.defaults | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py index b0f218b..941187e 100755 --- a/aurweb/scripts/notify.py +++ b/aurweb/scripts/notify.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import email.mime.text +import email.utils +import smtplib import subprocess import sys import textwrap @@ -63,7 +65,6 @@ class Notification: return body.rstrip() def send(self): - sendmail = aurweb.config.get('notifications', 'sendmail') sender = aurweb.config.get('notifications', 'sender') reply_to = aurweb.config.get('notifications', 'reply-to') reason = self.__class__.__name__ @@ -79,13 +80,26 @@ 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()) + sendmail = aurweb.config.get('notifications', 'sendmail') + if sendmail: + # send email using the sendmail binary specified in the + # configuration file + p = subprocess.Popen([sendmail, '-t', '-oi'], + stdin=subprocess.PIPE) + p.communicate(msg.as_bytes()) + else: + # send email using smtplib; no local MTA required + server_addr = aurweb.config.get('notifications', 'smtp-server') + + 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..23d46b0 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -47,7 +47,8 @@ window_length = 86400 [notifications] notify-cmd = /usr/local/bin/aurweb-notify -sendmail = /usr/bin/sendmail +sendmail = +smtp-server = localhost sender = notify@aur.archlinux.org reply-to = noreply@aur.archlinux.org