From 9a633ec26f0d16a98a6cb5b4bb77ba01a8db2f93 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Tue, 10 Apr 2018 22:30:57 -0500 Subject: [PATCH] osclib/util: provide mail_send(), modified from announcer.py. Depend on config for relay, from, and followup-to. --- osclib/conf.py | 8 ++++++++ osclib/util.py | 25 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/osclib/conf.py b/osclib/conf.py index 1cb4aecc..d333cd67 100644 --- a/osclib/conf.py +++ b/osclib/conf.py @@ -54,6 +54,10 @@ DEFAULT = { 'legal-review-group': 'legal-auto', 'repo-checker': 'repo-checker', 'pkglistgen-product-family-include': 'openSUSE:Leap:N', + 'mail-list': 'opensuse-factory@opensuse.org', + 'mail-maintainer': 'Dominique Leuenberger ', + 'mail-noreply': 'noreply@opensuse.org', + 'mail-release-list': 'opensuse-releaseteam@opensuse.org', }, r'openSUSE:(?PLeap:(?P[\d.]+))': { 'staging': 'openSUSE:%(project)s:Staging', @@ -94,6 +98,10 @@ DEFAULT = { 'pkglistgen-include-suggested': '1', 'pkglistgen-delete-kiwis-rings': 'openSUSE-ftp-ftp-x86_64.kiwi openSUSE-cd-mini-x86_64.kiwi', 'pkglistgen-delete-kiwis-staging': 'openSUSE-ftp-ftp-x86_64.kiwi openSUSE-cd-mini-x86_64.kiwi', + 'mail-list': 'opensuse-factory@opensuse.org', + 'mail-maintainer': 'Ludwig Nussel ', + 'mail-noreply': 'noreply@opensuse.org', + 'mail-release-list': 'opensuse-releaseteam@opensuse.org', }, r'SUSE:(?PSLE-15.*$)': { 'staging': 'SUSE:%(project)s:Staging', diff --git a/osclib/util.py b/osclib/util.py index 60775e01..151796e9 100644 --- a/osclib/util.py +++ b/osclib/util.py @@ -1,3 +1,4 @@ +from osc import conf from osclib.core import project_list_prefix @@ -79,3 +80,27 @@ def project_version(project): return version return None + +def mail_send(project, to, subject, body, from_key='maintainer', followup_to_key='release-list', dry=False): + from email.mime.text import MIMEText + import email.utils + import smtplib + + config = conf.config[project] + msg = MIMEText(body) + msg['Message-ID'] = email.utils.make_msgid() + msg['Date'] = email.utils.formatdate(localtime=1) + msg['From'] = config['mail-{}'.format(from_key)] + msg['To'] = to + followup_to = config.get('mail-{}'.format(followup_to_key)) + if followup_to: + msg['Mail-Followup-To'] = followup_to + msg['Subject'] = subject + + if dry: + print(msg.as_string()) + return + + s = smtplib.SMTP(config.get('mail-relay', 'relay.suse.de')) + s.sendmail(msg['From'], [msg['To']], msg.as_string()) + s.quit()