The frist email to myself by python

昨天用python模块给自己发了第一封电子邮件,真是激动

今天完善了一下。

 The frist email to myself by python

code:

 1 import smtplib
 2 from email.mime.text import MIMEText//email #包中加载部分功能
 3 from email.header import Header
 4 
 5 sever = smtplib.SMTP_SSL()#加密传输
 6 sever.connect('smtp.qq.com',465)#链接服务器
 7 
 8 username =input('使用邮箱')
 9 password =input('授权码')
10 to_addrs =['xxx.@qq.com']
11 12 sever.login(username,password) 13 14 text=''' 15 this is a good time! 16 my frist letters from python. 17 hope eveything.''' 18 19 msg=MIMEText(text,'plain','utf-8')#发送文本内容 20 msg['From']=Header(username) 21 msg['To']=Header(",".join(to_addrs)) 22 msg['Subject']=Header('welcom from python') 23 24 try: 25 sever.sendmail(username,to_addrs,msg.as_string()) 26 except: 27 print('发送失败,请重试') 28 29 sever.quit()

 

上一篇:成熟男人需要懂得的100件事


下一篇:window.onload()方法中代码顺序