From ffe14d7ed934845a780f38f65ace2842ececff8b Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 15 Mar 2017 09:52:09 -0400 Subject: [PATCH] fix mail sending Correct the logic related to parsing the server address so that the default is not overwritten if there is no @ in the address. Fix handling of a missing password by allowing an empty string to mean no password was given. Move the TO parsing out of the try/finally block so that errors in parsing the message are not swallowed by errors when we quit a server connection that wasn't opened properly. Change-Id: I73a24a4d87c0f4a5aabd302d8a7d2884e5513c31 Signed-off-by: Doug Hellmann --- releasetools/cmds/mail.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/releasetools/cmds/mail.py b/releasetools/cmds/mail.py index 973406d..80a1b75 100644 --- a/releasetools/cmds/mail.py +++ b/releasetools/cmds/mail.py @@ -39,20 +39,22 @@ def main(): user = None pw = None + server = args.server - if args.server.find('@'): - creds, _, args.server = args.server.partition('@') + 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) - server = smtplib.SMTP(args.server) + tolist = [address.strip() for address in msg['to'].split(",")] + + server = smtplib.SMTP(server) if args.verbose: server.set_debuglevel(True) try: - tolist = [address.strip() for address in msg['to'].split(",")] - if pw is not None: + if pw: server.starttls() server.login(user, pw) server.sendmail(msg['from'], tolist, msg.as_string())