mail: Fix auth over starttls. (#24089)

This commit is contained in:
Konstantin Shalygin 2017-08-19 01:13:24 +07:00 committed by Chris Alfonso
parent 03b888052b
commit 343da35381

View file

@ -246,7 +246,6 @@ def main():
sender_phrase, sender_addr = parseaddr(sender) sender_phrase, sender_addr = parseaddr(sender)
secure_state = False secure_state = False
code = 0 code = 0
auth_flag = ""
if not body: if not body:
body = subject body = subject
@ -269,7 +268,6 @@ def main():
module.fail_json(rc=1, msg='Unable to Connect to %s:%s: %s' % module.fail_json(rc=1, msg='Unable to Connect to %s:%s: %s' %
(host, port, to_native(e)), exception=traceback.format_exc()) (host, port, to_native(e)), exception=traceback.format_exc())
if (secure == 'always'): if (secure == 'always'):
try: try:
smtp = smtplib.SMTP_SSL(timeout=timeout) smtp = smtplib.SMTP_SSL(timeout=timeout)
@ -286,8 +284,6 @@ def main():
module.fail_json(rc=1, msg='Helo failed for host %s:%s: %s' % module.fail_json(rc=1, msg='Helo failed for host %s:%s: %s' %
(host, port, to_native(e)), exception=traceback.format_exc()) (host, port, to_native(e)), exception=traceback.format_exc())
auth_flag = smtp.has_extn('AUTH')
if secure in ('try', 'starttls'): if secure in ('try', 'starttls'):
if smtp.has_extn('STARTTLS'): if smtp.has_extn('STARTTLS'):
try: try:
@ -303,7 +299,7 @@ def main():
module.fail_json(rc=1, msg='StartTLS is not offered on server %s:%s' % (host, port)) module.fail_json(rc=1, msg='StartTLS is not offered on server %s:%s' % (host, port))
if username and password: if username and password:
if auth_flag: if smtp.has_extn('AUTH'):
try: try:
smtp.login(username, password) smtp.login(username, password)
except smtplib.SMTPAuthenticationError: except smtplib.SMTPAuthenticationError: