python SMTP邮件发送

import stmplib

from email.mime.text import MIMEText 

from email.Header import Header

mailhost='stmp.qq.com'  #设置服务器

mailuser='XXXXXXX@foxmail.com' #使用时亲测不能用qq.com,

maipass='XXXXXXXX'#不是登陆密码,填写授权码,在邮箱中设置smtp服务。

sender='XXXXXX@foxmail.com' #发件人

receiver=['XXXXXXXX']  #或者添加列表

message['from']=Header('数据中心','utf-8')  #显示发送的

message['to']=Header('XX','utf-8')#显示发送给谁

message=MIMEText('python测试','plain','utf-8')#主要内容

stmpobj=stmplib.SMTP()#实例化

stmpobj.connect(maihost,25)#连接服务器,设置端口号

stmpobj.login(mailuser,mailpass)#登陆

stmpobj.sendmail(sender,receiver,message.as_sring()) #发送

print('发送成功!')

 

posted @ 2018-11-13 10:48  The_Chain  阅读(190)  评论(0编辑  收藏  举报