diff --git a/openstack_releases/cmds/mail.py b/openstack_releases/cmds/mail.py new file mode 100644 index 0000000000..a1c874ae80 --- /dev/null +++ b/openstack_releases/cmds/mail.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +"""Read an email message and send it through localhost. + +This is a separate script from the release notes email generator +because it might be used for other things and it might not be used +when notes are being send from a developer's system. + +""" + +from __future__ import print_function + +import argparse +import email +import smtplib + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--server', default='lists.openstack.org', + help=('the SMTP server Valid forms are: server, ' + 'server:port, user:pw@server or ' + 'user:pw@server:port. Default: %(default)s')) + parser.add_argument('-v', dest='verbose', + action='store_true', default=False, + help='turn on extra debugging output') + parser.add_argument('infile', help='the file containing the email') + args = parser.parse_args() + + user = None + pw = None + server = args.server + + if '@' in server: + creds, _, server = args.server.partition('@') + user, _, pw = creds.partition(':') + + with open(args.infile, 'r') as f: + msg = email.message_from_file(f) + + tolist = [address.strip() for address in msg['to'].split(",")] + + server = smtplib.SMTP(server) + if args.verbose: + server.set_debuglevel(True) + try: + if pw: + server.starttls() + server.login(user, pw) + server.sendmail(msg['from'], tolist, msg.as_string().encode('utf-8')) + finally: + server.quit() diff --git a/setup.cfg b/setup.cfg index ba2562f416..3a3f01a18f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,7 @@ console_scripts = make-tracking-pad = openstack_releases.cmds.make_tracking_pad:main propose-library-branches = openstack_releases.cmds.propose_library_branches:main edit-deliverable = openstack_releases.cmds.edit_deliverable:main + send-mail = openstack_releases.cmds.mail:main [extras] sphinxext =