python登录QQ邮箱发信的实现代码
(编辑:jimmy 日期: 2024/11/17 浏览:3 次 )
复制代码 代码如下:
# -*- coding: cp936 -*-
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib, datetime
#创建一个带附件的实例
msg = MIMEMultipart()
#构造附件
att = MIMEText(open('f:\\文件名.doc', 'rb').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="文件名.doc"'
msg.attach(att)
#加邮件头
msg['to'] = '790896688@qq.com'
msg['from'] = '12508680287@qq.com'
msg['subject'] = Header('测试 (' + str(datetime.date.today()) + ')','gb2312')
#发送邮件
server = smtplib.SMTP('smtp.qq.com')
server.login('137951467','123456')
error=server.sendmail(msg['from'], msg['to'],msg.as_string())
server.close
print error
# -*- coding: cp936 -*-
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
import smtplib, datetime
#创建一个带附件的实例
msg = MIMEMultipart()
#构造附件
att = MIMEText(open('f:\\文件名.doc', 'rb').read(), 'base64', 'gb2312')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="文件名.doc"'
msg.attach(att)
#加邮件头
msg['to'] = '790896688@qq.com'
msg['from'] = '12508680287@qq.com'
msg['subject'] = Header('测试 (' + str(datetime.date.today()) + ')','gb2312')
#发送邮件
server = smtplib.SMTP('smtp.qq.com')
server.login('137951467','123456')
error=server.sendmail(msg['from'], msg['to'],msg.as_string())
server.close
print error
下一篇:多线程爬虫批量下载pcgame图片url 保存为xml的实现代码