Update sendemail.py

This commit is contained in:
FlyPython
2019-09-30 17:56:08 +08:00
committed by GitHub
parent fb56f858f4
commit c79818e78b

View File

@@ -25,11 +25,8 @@ message['To'] = ['flypython.com@gmail.com']
#登录并发送邮件 #登录并发送邮件
try: try:
smtpObj = smtplib.SMTP() smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信, 端口一般是465
#连接到服务器 smtpObj.login(mail_user, mail_pass) # 登录验证
smtpObj.connect(mail_host,25)
#登录到服务器
smtpObj.login(mail_user,mail_pass)
#发送 #发送
smtpObj.sendmail( smtpObj.sendmail(
sender,receivers,message.as_string()) sender,receivers,message.as_string())
@@ -37,4 +34,4 @@ try:
smtpObj.quit() smtpObj.quit()
print('success') print('success')
except smtplib.SMTPException as e: except smtplib.SMTPException as e:
print('error',e) #打印错误 print('error',e) #打印错误