osclib/util: provide mail_send(), modified from announcer.py.
Depend on config for relay, from, and followup-to.
This commit is contained in:
parent
b52f890bb9
commit
9a633ec26f
@ -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 <dimstar@suse.de>',
|
||||
'mail-noreply': 'noreply@opensuse.org',
|
||||
'mail-release-list': 'opensuse-releaseteam@opensuse.org',
|
||||
},
|
||||
r'openSUSE:(?P<project>Leap:(?P<version>[\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 <ludwig.nussel@suse.de>',
|
||||
'mail-noreply': 'noreply@opensuse.org',
|
||||
'mail-release-list': 'opensuse-releaseteam@opensuse.org',
|
||||
},
|
||||
r'SUSE:(?P<project>SLE-15.*$)': {
|
||||
'staging': 'SUSE:%(project)s:Staging',
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user