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 邮件的更多相关文章

  1. python邮件发送脚本

    转自:http://phinecos.cnblogs.com/ #!/usr/bin/python #coding=utf-8 #@author:dengyike #@date:2010-09-28 ...

  2. centos 7 keepalived故障邮件通知实战(附Python邮件发送脚本)

    centos 7 keepalived故障邮件通知实战(附Python邮件发送脚本) #####################     sendmail.py  begin     ######## ...

  3. python 邮件基础篇

    python 操作邮件,不是很方便,说实话还不是理解的特别透彻,这次想把自己碰到的东西总结下来 邮件有imap,pop,imap协议,这次使用的是imap4协议,主要用了imap4和mail类, 代码 ...

  4. python 邮件发送 脚本

    import smtplib from email.header import Header from email.mime.text import MIMEText from_addr = 'XXX ...

  5. Python 邮件发送

    python发送各类邮件的主要方法   python中email模块使得处理邮件变得比较简单,今天着重学习了一下发送邮件的具体做法,这里写写自己的的心得,也请高手给些指点.     一.相关模块介绍 ...

  6. python邮件SMTP的GUI编程

    写的是python中smtp的gui编程,用的163邮箱给qq邮箱发送邮件做测试,如果你发现你的发送失败,试着用以下方法解决: 1.网页登陆你的邮箱,设置中查看smtp是否开启,比如163邮箱的smt ...

  7. Python邮件发送脚本(Linux,Windows)通用

    脚本 #!/usr/bin/python #-*- coding:utf-8 -*- #Python Mail for chenglee #if fileformat=dos, update file ...

  8. python邮件处理

    SMTP SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.Python对SMTP支持有 ...

  9. python邮件

    解读Python发送邮件 Python发送邮件需要smtplib和email两个模块.也正是由于我们在实际工作中可以导入这些模块,才使得处理工作中的任务变得更加的简单.今天,就来好好学习一下使用Pyt ...

随机推荐

  1. linux下给网卡加VLAN标签和私网地址

    1.加载8021q协议 moprobe 8021q 2.安装必要的包 yum -y groupinstall base linux 3.添加私网地址(写到开机启动项) vconfig add bond ...

  2. centos7 yum 方式安装nginx

    centos7系统库中默认是没有nginx的rpm包的,所以我们自己需要先更新下rpm依赖库 (1)使用yum安装nginx需要包括Nginx的库,安装Nginx的库 #rpm -Uvh http:/ ...

  3. rewrite规则中参数多于9个的处理方式 apache nginx

    RewriteRule ^index-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)(.*)$ $9&a ...

  4. XSS常用技巧

    一般发现一个xss漏洞后要做的基本上就是这些: 1. 伪造请求 使用$_REQUEST或$_GET 首先我们要找找该网站使用的程序是不是在网上能找到源码,如果能找到源码的话,就去分析后台管理员更改密码 ...

  5. 关于 OJ1575的参考题解

    #include <stdio.h>int main(){ int a,b; scanf("%d",&a); b=0; while(a) { b+=a%10; ...

  6. Ember.js入门教程、博文汇总

    第一章 对象模型 Ember.js 入门指南——类的定义.初始化.继承 Ember.js 入门指南——类的扩展(reopen) Ember.js 入门指南——计算属性(compute properti ...

  7. 图片懒加载--判断div ul中的li是否已经滑动到可视区域里

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  8. Webpack、Browserify和Gulp

    https://www.zhihu.com/question/37020798 https://www.zhihu.com/question/35479764

  9. Java Integer(-128~127)值的==和equals比较产生的思考

    最近在项目中遇到一个问题,两个值相同的Integer型值进行==比较时,发现Integer其中的一些奥秘,顺便也复习一下==和equals的区别,先通过Damo代码解释如下: System.out.p ...

  10. selenium ide脚本回放出现element not found

    原因: 点击按钮,没有设置时间延迟,而页面加载,需要时间:当页面元素未加载完全,执行点击事件,就会报错:element... not found. 解决方案: 在点击事件前添加新的COMMAND.设置 ...