python3.4实现邮件发送功能
本文实例为大家分享了python实现邮件发送功能的具体代码,供大家参考,具体内容如下
importsmtplib
importos
fromemail.mime.textimportMIMEText
fromemail.mime.multipartimportMIMEMultipart
fromemailimportencoders
user='*******@qq.com'
pwd='*******'
to=['******@139.com','******@qq.com']
msg=MIMEMultipart()
msg['Subject']='这里是主题...'
content1=MIMEText('这里是正文!','plain','utf-8')
msg.attach(content1)
attfile='C:\\Users\\hengli\\Pictures\\CameraMan\\哈哈.doc'
basename=os.path.basename(attfile)
fp=open(attfile,'rb')
att=MIMEText(fp.read(),'base64','utf-8')
att["Content-Type"]='application/octet-stream'
att.add_header('Content-Disposition','attachment',filename=('gbk','',basename))
encoders.encode_base64(att)
msg.attach(att)
#-----------------------------------------------------------
s=smtplib.SMTP('smtp.qq.com')
s.login(user,pwd)
s.sendmail(user,to,msg.as_string())
print('发送成功')
s.close()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短