博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python3发送邮件02(简单例子,带附件)
阅读量:2243 次
发布时间:2019-05-09

本文共 1817 字,大约阅读时间需要 6 分钟。

#!/usr/bin/env python # -*- coding:UTF-8 -*-
import os import smtplib from email.header import Header from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart #第3方smtp服务器 host="smtp.163.com" user="xxx" password="xxx" sender="xxx@163.com" # receiver="xxx" #多收件人 receiver=["xxx","xxx"] encoding="utf-8" bencoding="base64" #plain 文本内容 html 网页内容 type="html" # type="plain" subject="python内容为html格式" # subject="python内容为文本格式" content="""python主题:

Python 邮件发送测试...

这是一个链接

""" # content="""python主题:这是邮件内容""" #文本内容:plain html内容:html # message=MIMEText(content,type,encoding) # message['From']=Header('w3cschool from',encoding) # message['To']=Header('w3cschool to',encoding) # message['To']=";".join(receiver) # message['Subject']=Header(subject,encoding) path=os.getcwd() file1="excelpractise01.py" file2="excelpracties02.py" mimeContent=MIMEText(content,type,encoding) #邮件正文 message=MIMEMultipart() message['From']=Header('hello world',encoding) # message['to']=Header('this is my results',encoding) message['to']=";".join(receiver) message['Subject']=Header(subject,encoding) message.attach(mimeContent) #邮件附件01 att1=MIMEText(open(path+"\\"+file1,'rb').read(),bencoding,encoding) att1['Content-Type']="application/octet-stream" att1['Content-Disposition']="attachment;filename='%s'"%(file1) message.attach(att1) #邮件附件02 att2=MIMEText(open(path+"\\"+file2,'rb').read(),bencoding,encoding) att2['Content-Type']="application/octet-stream" att2['Content-Disposition']="attachment;filename='%s"%(file2) message.attach(att2) try: # path=os.getcwd() # print(path) smtp=smtplib.SMTP() smtp.connect(host,0) smtp.login(user,password) smtp.sendmail(sender,receiver,message.as_string()) smtp.quit() except: print("error")

转载于:https://www.cnblogs.com/NiceTime/p/10069977.html

你可能感兴趣的文章
Struts2中的session、request、respsonse获取方法
查看>>
如何理解MVC模型
查看>>
SpringMVC中乱码解决方案
查看>>
SpringMVC中时间格式转换的解决方案
查看>>
post和get请求相关知识点
查看>>
关于try finally 中的return语句的问题
查看>>
RequestBody/ResponseBody处理Json数据
查看>>
springmvc请求参数获取的几种方法
查看>>
在eclipse中创建和myeclipse一样的包结构
查看>>
Java中的IO流
查看>>
java中的关键字
查看>>
如果某个方法是静态的,它的行为就不具有多态性
查看>>
优化Hibernate所鼓励的7大措施
查看>>
Java 8系列之重新认识HashMap
查看>>
HashMap 、 ArrayList、String 重写了equals方法 而Object类(比如User)没有重写
查看>>
Servlet的生命周期
查看>>
Object中的getClass()返回的是当前运行的类
查看>>
加载驱动程序的方法
查看>>
深入理解java异常处理机制
查看>>
object类的基本方法
查看>>