python3.4实现邮件发送功能

yipeiwu_com6年前Python基础

本文实例为大家分享了python实现邮件发送功能的具体代码,供大家参考,具体内容如下

import smtplib 
import os 
from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 
from email import encoders 
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() 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Pandas-Cookbook 时间戳处理方式

# -*-coding:utf-8-*- # by kevinelstri # 2017.2.17 # ----------...

Python3 replace()函数使用方法

描述 replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。 语法 replace()方法语法: st...

python设计tcp数据包协议类的例子

python设计tcp数据包协议类的例子

一. 问题描述 在tcp编程中,最需要解决的就是粘包分包问题。所以,我们需要在每个数据包前面加上数据包的长度用以分割粘连的包。 二. 包结构的设计 包的组成:包长度+数据域 包长度:用4...

简单介绍Python中的RSS处理

RSS 是一个可用多种扩展来表示的缩写:“RDF 站点摘要(RDF Site Summary)”、“真正简单的辛迪加(Really Simple Syndication)”、“丰富站点摘...

Python开发的单词频率统计工具wordsworth使用方法

Python开发的单词频率统计工具wordsworth使用方法

使用方法: python wordsworth --filename textfile.txt python wordsworth -f textfile.txt 分析结果:...