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 ...
随机推荐
- Git 命令清单
这份命令清单并不完善,后期会根据使用情况再进行更改. 操作分支项目 1 下载仓库的一个分支(baooab-patch-1)的代码 git clone -b baooab-patch-1 https:/ ...
- 模板——Tarjan
#include <cstdio> #include <cstring> #include <iostream> #include <vector> u ...
- Oracle 截取字符串
如下有一个创建函数的代码,是将一穿字符串按照逗号‘,’分割成若干段 create or replace function SplitStringByComma(aName in varchar2) r ...
- NSUserDefaults 简介,使用 NSUserDefaults 存储自定义对象
摘要: NSUserDefaults适合存储轻量级的本地数据,一些简单的数据(NSString类型的)例如密码,网址等,NSUserDefaults肯定是首选,但是如果我们自定义了一个对象,对象保存的 ...
- linux @后面的主机名如何修改
@后面的为linux系统的主机名 临时修改方法:执行 hostname 主机名再执行 bash 永久修改方法:修改配置文件/etc/sysconfig/network修改参数HOSTNAME=主机名永 ...
- 附录1· 初识Linux操作系统
编译 GCC汇编器 NASM链接 LD调试 GDBBochsBochs模拟器微内核 单内核=====================Linux特点=====================以下所有内 ...
- LVS
1.LVS-NAT, DNAT(多目标) 2.LVS-DR(Direct Routing) 返回报文不经过Direct real server 不能跨越路由 调度算法:Scheduling 静态方法 ...
- 进fastreboot
1.红米1s 关机后,开机键+音量键下 同时按 2.红米note 关机后,开机键+音量键上 同时按 3. 4. 5.
- pycharm快捷键、常用设置、包管理
pycharm快捷键.常用设置.包管理 在PyCharm安装目录 /opt/pycharm-3.4.1/help目录下可以找到ReferenceCard.pdf快捷键英文版说明 or 打开pychar ...
- C#socket通信-----多线程
我在之前的socket通信的基础上做了一点改进,使用多线程来使用,程序更加简洁实用.不足之处请指教哦! 话不多说,之前的随笔也有介绍,直接上代码啦! 服务端socket(serverSocket): ...