File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88email_password = ''
99email_send = 'zhxhcoder@qq.com'
1010
11- subject = 'subjec11t'
11+ # 主题
12+ subject = '主题-这是Python发送的邮件'
1213
1314msg = MIMEMultipart ()
1415msg ['From' ] = email_user
1516msg ['To' ] = email_send
1617msg ['Subject' ] = subject
1718
18- body = 'Hi there, sending this email from Python!'
19- msg .attach (MIMEText (body , 'plain' ))
20-
19+ # 附件
2120filename = 'QR.png'
2221attachment = open (filename , 'rb' )
23-
2422part = MIMEBase ('application' , 'octet-stream' )
2523part .set_payload (attachment .read ())
2624encoders .encode_base64 (part )
2725part .add_header ('Content-Disposition' , "attachment; filename= " + filename )
28-
2926msg .attach (part )
27+
28+ # 内容
29+ body = '内容-这是远程发来的邮件,请注意接收并查收附件' + filename
30+ msg .attach (MIMEText (body , 'plain' ))
31+
3032text = msg .as_string ()
3133server = smtplib .SMTP_SSL ('smtp.qq.com' , 465 )
3234# server.starttls()
3335server .login (email_user , email_password )
34-
36+ print ( "邮件发送..." )
3537server .sendmail (email_user , email_send , text )
36-
38+ print ( "发送成功" )
3739server .quit ()
You can’t perform that action at this time.
0 commit comments