Add support for mail servers that require a login
When running announce.sh from my local developer workstation I cannot connect to lisst.openstack.org. I know my ISP filters outbound traffic to port TCP:25 but there may be additional reasons. This chnage enhances the --server option to allow you to provide username, password hostname and TCP port with which to contact a mail server. This is not a complete solution but it makes it much easier for me to work locally if needed. Change-Id: I1a0f03341d1962a30c0737b59d32e8e68c28644b
This commit is contained in:
parent
9c72009874
commit
8dab9bad19
|
@ -28,13 +28,22 @@ import smtplib
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--server', default='lists.openstack.org',
|
parser.add_argument('--server', default='lists.openstack.org',
|
||||||
help='the SMTP server')
|
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',
|
parser.add_argument('-v', dest='verbose',
|
||||||
action='store_true', default=False,
|
action='store_true', default=False,
|
||||||
help='turn on extra debugging output')
|
help='turn on extra debugging output')
|
||||||
parser.add_argument('infile', help='the file containing the email')
|
parser.add_argument('infile', help='the file containing the email')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
user = None
|
||||||
|
pw = None
|
||||||
|
|
||||||
|
if args.server.find('@'):
|
||||||
|
creds, _, args.server = args.server.partition('@')
|
||||||
|
user, _, pw = creds.partition(':')
|
||||||
|
|
||||||
with open(args.infile, 'r') as f:
|
with open(args.infile, 'r') as f:
|
||||||
msg = email.message_from_file(f)
|
msg = email.message_from_file(f)
|
||||||
|
|
||||||
|
@ -43,6 +52,9 @@ def main():
|
||||||
server.set_debuglevel(True)
|
server.set_debuglevel(True)
|
||||||
try:
|
try:
|
||||||
tolist = [address.strip() for address in msg['to'].split(",")]
|
tolist = [address.strip() for address in msg['to'].split(",")]
|
||||||
|
if pw is not None:
|
||||||
|
server.starttls()
|
||||||
|
server.login(user, pw)
|
||||||
server.sendmail(msg['from'], tolist, msg.as_string())
|
server.sendmail(msg['from'], tolist, msg.as_string())
|
||||||
finally:
|
finally:
|
||||||
server.quit()
|
server.quit()
|
||||||
|
|
Loading…
Reference in New Issue