Skip to content

Commit c79818e

Browse files
author
FlyPython
authored
Update sendemail.py
1 parent fb56f85 commit c79818e

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

sendemail.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,13 @@
2525

2626
#登录并发送邮件
2727
try:
28-
smtpObj = smtplib.SMTP()
29-
#连接到服务器
30-
smtpObj.connect(mail_host,25)
31-
#登录到服务器
32-
smtpObj.login(mail_user,mail_pass)
28+
smtpObj = smtplib.SMTP_SSL(mail_host, 465) # 启用SSL发信, 端口一般是465
29+
smtpObj.login(mail_user, mail_pass) # 登录验证
3330
#发送
3431
smtpObj.sendmail(
3532
sender,receivers,message.as_string())
3633
#退出
3734
smtpObj.quit()
3835
print('success')
3936
except smtplib.SMTPException as e:
40-
print('error',e) #打印错误
37+
print('error',e) #打印错误

0 commit comments

Comments
 (0)