python 邮件
1:文件形式的邮件
01.#!/usr/bin/env python3
02.#coding: utf-8
03.import smtplib
04.from email.mime.text import MIMEText
05.from email.header import Header
06.
07.sender = '***'8.receiver = '***'9.subject = 'python email test'
10.smtpserver = 'smtp.163.com'
11.username = '***'
12.password = '***'
13.
14.msg = MIMEText('你好','text','utf-8')#中文需参数‘utf-8’,单字节字符不需要
15.msg['Subject'] = Header(subject, 'utf-8')
16.
17.smtp = smtplib.SMTP()
18.smtp.connect('smtp.163.com')
19.smtp.login(username, password)
20.smtp.sendmail(sender, receiver, msg.as_string())
21.smtp.quit()
01.#!/usr/bin/env python3
02.#coding: utf-8
03.import smtplib
04.from email.mime.text import MIMEText
05.
06.sender = '***'
07.receiver = '***'8.subject = 'python email test'9.smtpserver = 'smtp.163.com'
10.username = '***'
11.password = '***'
12.
13.msg = MIMEText('<html><h1>你好</h1></html>','html','utf-8')
14.
15.msg['Subject'] = subject
16.
17.smtp = smtplib.SMTP()
18.smtp.connect('smtp.163.com')
19.smtp.login(username, password)
20.smtp.sendmail(sender, receiver, msg.as_string())
21.smtp.quit() 带图片的HTML邮件 01.#!/usr/bin/env python3
02.#coding: utf-8
03.import smtplib
04.from email.mime.multipart import MIMEMultipart
05.from email.mime.text import MIMEText
06.from email.mime.image import MIMEImage
07.
08.sender = '***'9.receiver = '***'
10.subject = 'python email test'
11.smtpserver = 'smtp.163.com'
12.username = '***'
13.password = '***'
14.
15.msgRoot = MIMEMultipart('related')
16.msgRoot['Subject'] = 'test message'
17.
18.msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>good!','html','utf-8')
19.msgRoot.attach(msgText)
20.
21.fp = open('h:\\python\\1.jpg', 'rb')
22.msgImage = MIMEImage(fp.read())
23.fp.close()
24.
25.msgImage.add_header('Content-ID', '<image1>')
26.msgRoot.attach(msgImage)
27.
28.smtp = smtplib.SMTP()
29.smtp.connect('smtp.163.com')
30.smtp.login(username, password)
31.smtp.sendmail(sender, receiver, msgRoot.as_string())
32.smtp.quit() 带附件的邮件 01.#!/usr/bin/env python3
02.#coding: utf-8
03.import smtplib
04.from email.mime.multipart import MIMEMultipart
05.from email.mime.text import MIMEText
06.from email.mime.image import MIMEImage
07.
08.sender = '***'9.receiver = '***'
10.subject = 'python email test'
11.smtpserver = 'smtp.163.com'
12.username = '***'
13.password = '***'
14.
15.msgRoot = MIMEMultipart('related')
16.msgRoot['Subject'] = 'test message'
17.
18.#构造附件
19.att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8')
20.att["Content-Type"] = 'application/octet-stream'
21.att["Content-Disposition"] = 'attachment; filename="1.jpg"'
22.msgRoot.attach(att)
23.
24.smtp = smtplib.SMTP()
25.smtp.connect('smtp.163.com')
26.smtp.login(username, password)
27.smtp.sendmail(sender, receiver, msgRoot.as_string())
28.smtp.quit()
python 邮件的更多相关文章
- python邮件发送脚本
转自:http://phinecos.cnblogs.com/ #!/usr/bin/python #coding=utf-8 #@author:dengyike #@date:2010-09-28 ...
- centos 7 keepalived故障邮件通知实战(附Python邮件发送脚本)
centos 7 keepalived故障邮件通知实战(附Python邮件发送脚本) ##################### sendmail.py begin ######## ...
- python 邮件基础篇
python 操作邮件,不是很方便,说实话还不是理解的特别透彻,这次想把自己碰到的东西总结下来 邮件有imap,pop,imap协议,这次使用的是imap4协议,主要用了imap4和mail类, 代码 ...
- python 邮件发送 脚本
import smtplib from email.header import Header from email.mime.text import MIMEText from_addr = 'XXX ...
- Python 邮件发送
python发送各类邮件的主要方法 python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法,这里写写自己的的心得,也请高手给些指点. 一.相关模块介绍 ...
- python邮件SMTP的GUI编程
写的是python中smtp的gui编程,用的163邮箱给qq邮箱发送邮件做测试,如果你发现你的发送失败,试着用以下方法解决: 1.网页登陆你的邮箱,设置中查看smtp是否开启,比如163邮箱的smt ...
- Python邮件发送脚本(Linux,Windows)通用
脚本 #!/usr/bin/python #-*- coding:utf-8 -*- #Python Mail for chenglee #if fileformat=dos, update file ...
- python邮件处理
SMTP SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.Python对SMTP支持有 ...
- python邮件
解读Python发送邮件 Python发送邮件需要smtplib和email两个模块.也正是由于我们在实际工作中可以导入这些模块,才使得处理工作中的任务变得更加的简单.今天,就来好好学习一下使用Pyt ...
随机推荐
- 《Spring MVC学习指南》怎么样?答:书名具有很大的欺骗性
2016年6月21日 最近,因为工作需要,我从网上买了一本<Spring MVC学习指南>,ISBN编号: 978-7-115-38639-7,定价:49.00元.此书是[美]Paul D ...
- word域3
WORD是文字处理软件,我们在日常处理一些文字时经常遇到一些问题,如:各种公式的录入,尽管Word都提供了"公式编辑器",但其插入的却是"对象",有时排版会感觉 ...
- 【leetcode❤python】 165. Compare Version Numbers
#-*- coding: UTF-8 -*-class Solution(object): def compareVersion(self, version1, version2): ...
- vnc连接kali 2.0 报错:A problem has occurred and the system can't recover.
kali版本: root@kali:~# uname -a Linux kali -kali1-amd64 # SMP Debian -7kali2 (--) x86_64 GNU/Linux 第一步 ...
- matlab basic operation command
Matlab basic operation: >> 5+6 ans = 11 >> 3*4 ans = 12 >> 2^6 ans = 64 >> 1 ...
- Ajax --- 数据请求
下面主要介绍(JS原生)数据请求的主要步骤: Ajax 数据请求步骤: 1.创建XMLHttpRequest对象 2.准备数据发送 3.执行发送 4.指定回掉函数 第一步:创建XMLHttpReque ...
- iOS runloop初步学习
参考: http://www.aichengxu.com/view/43297111. 定义:其实它内部就是do-while循环,在这个循环内部不断地处理各种任务(比如Source.Timer.Obs ...
- iOS app 企业内部发布及HTTPS服务器配置
转自: http://www.cnblogs.com/cocoajin/p/4082488.html iOS企业内部发布及HTTPS服务器配置 一:所需的条件 1. 苹果开发者证书,企业版 299$ ...
- Sublime Text2 javascript格式化插件JsFormat
一.安装方法: 按下快捷键 Ctrl+Alt+p 打开命令面板 输入install 这时下拉框第一项就会显示安装包控制器(这个需要初始化安装,不明白的搜索本站关于sublime Text2 的介绍) ...
- 微软亚洲实验室一篇超过人类识别率的论文:Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification ImageNet Classification
在该文章的两大创新点:一个是PReLU,一个是权值初始化的方法.下面我们分别一一来看. PReLU(paramter ReLU) 所谓的PRelu,即在 ReLU激活函数的基础上加入了一个参数,看一个 ...