File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import smtplib
2+ from email .mime .text import MIMEText
3+ #设置服务器所需信息
4+
5+ #163邮箱服务器地址
6+ mail_host = 'smtp.163.com'
7+ #163用户名
8+ mail_user = 'flypython***'
9+ #密码(163等邮箱为授权码)
10+ mail_pass = '7******x'
11+
12+ #发送地址
13+ sender = 'flypython.com'
14+ #发送内容为纯文本
15+ message = MIMEText ('Hello World ! This is from FlyPython!' ,'plain' ,'utf-8' )
16+ #email主题
17+ message ['Subject' ] = 'FlyPython'
18+ #发送地址
19+ message ['From' ] = sender
20+ #接受地址
21+ receivers = ['flypython.com@gmail.com' ]
22+ #接受地址的名称
23+ message ['To' ] = ['flypython.com@gmail.com' ]
24+
25+
26+ #登录并发送邮件
27+ try :
28+ smtpObj = smtplib .SMTP ()
29+ #连接到服务器
30+ smtpObj .connect (mail_host ,25 )
31+ #登录到服务器
32+ smtpObj .login (mail_user ,mail_pass )
33+ #发送
34+ smtpObj .sendmail (
35+ sender ,receivers ,message .as_string ())
36+ #退出
37+ smtpObj .quit ()
38+ print ('success' )
39+ except smtplib .SMTPException as e :
40+ print ('error' ,e ) #打印错误
You can’t perform that action at this time.
0 commit comments