Commit 4f767044 authored by shenshuo's avatar shenshuo

tls 发送邮件增加端口

parent 135f1a83
......@@ -18,7 +18,7 @@ import uuid
class SendMail(object):
def __init__(self, mail_host, mail_port, mail_user, mail_password, mail_ssl):
def __init__(self, mail_host, mail_port, mail_user, mail_password, mail_ssl, mail_tls=False):
"""
:param mail_host: SMTP主机
:param mail_port: SMTP端口
......@@ -31,6 +31,7 @@ class SendMail(object):
self.__mail_user = mail_user
self.__mail_password = mail_password
self.mail_ssl = mail_ssl
self.mail_tls = mail_tls
def send_mail(self, to_list, subject, content, subtype='plain', att=None):
"""
......@@ -67,9 +68,9 @@ class SendMail(object):
server.login(self.__mail_user, self.__mail_password) # 登录操作
server.sendmail(self.__mail_user, to_list.split(','), msg.as_string())
server.close()
else:
elif self.mail_tls:
# print('Use TLS SendMail')
'''使用普通模式'''
'''使用TLS模式'''
server = smtplib.SMTP()
server.connect(self.mail_host, self.mail_port) # 连接服务器
server.ehlo()
......@@ -79,6 +80,15 @@ class SendMail(object):
server.sendmail(self.__mail_user, to_list.split(','), msg.as_string())
server.close()
return True
else:
'''使用普通模式'''
server = smtplib.SMTP()
server.connect(self.mail_host, self.mail_port) # 连接服务器
server.ehlo()
server.login(self.__mail_user, self.__mail_password) # 登录操作
server.sendmail(self.__mail_user, to_list.split(','), msg.as_string())
server.close()
return True
except Exception as e:
print(str(e))
return False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment