Python 发邮件例子


例子

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2019-04-23 16:12:33
# @Author : BenLam
# @Link : https://www.cnblogs.com/BenLam/ import smtplib
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart #发送邮箱服务器
smtpserver='smtp.mxhichina.com' #发送邮箱用户/密码
user='tester@qq.com'
password='123456' #发送人
sender='tester@qq.com'
#收件人
receiver='tester@qq.com'
#主题
subject='test E-mail'
msgRoot=MIMEMultipart('test') #正文
content='测试邮件地址!'
cont=MIMEText(content,'plain','utf-8') #附件
file=open('C:\\bug.txt','rb').read()
mark=MIMEText(file,'base64','utf-8')
mark["Content-Type"]='application/octet-stream'
mark["Content-Disposition"]='attachment;filename="bug.txt"' msgRoot['Subject'] = subject
msgRoot.attach(cont)
msgRoot.attach(mark) #开始发送邮件
smtp=smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(user, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()

结果:

Python 发邮件例子的更多相关文章

  1. 使用python发邮件

    使用python发邮件 网上有很多发邮件的例子,本人在网上找了一份,稍加修改后使用 上源码 # encoding=utf-8 from email.mime.image import MIMEImag ...

  2. python发邮件遇到的端口号问题

    在学习使用python发邮件的过程中, 遇到了一个问题:由于测试的时候使用的是QQ邮箱,要求必须使用SSL/TLS加密,所以有了下面的代码, from email.mime.text import M ...

  3. 如何用python发邮件

    python发送各类邮件的主要方法 一.相关模块介绍 发送邮件主要用到了smtplib和email两个模块,这里首先就两个模块进行一下简单的介绍:     1.smtplib模块 smtplib.SM ...

  4. [转]简单三步,用 Python 发邮件

    https://zhuanlan.zhihu.com/p/24180606 0. 前言 发送电子邮件是个很常见的开发需求.比如你写了个监控天气的脚本,发现第二天要下雨,或者网站上关注的某个商品降价了, ...

  5. Python—发邮件总结

    来自: http://my.oschina.net/jhao104/blog/613774 1.登录SMTP服务器 首先使用网上的方法(这里使用163邮箱,smtp.163.com是smtp服务器地址 ...

  6. 人生苦短之Python发邮件

    #coding=utf-8 import smtplib from email.mime.base import MIMEBase from email.mime.image import MIMEI ...

  7. python 发邮件-带附件-文本-html

    #!/usr/bin/python # encoding=utf-8 # Filename: send_email.py from email.mime.image import MIMEImage ...

  8. python 发邮件 utf-8

    import smtplib from operator import itemgetter, attrgetter from email.mime.text import MIMEText from ...

  9. 用python发邮件实例

    发QQ邮件 首先确认发件方是否打开了SMTP服务,去QQ邮箱的设置中查看,如果没有请自行开启. from email.header import Header from email.mime.text ...

随机推荐

  1. linux下构建SVN

    1. 安装subversion#yum -y install subversion2. 安装好了之后 新建一个svn目录#mkdir /home/svn3. 新建两个版本仓库#svnadmin cre ...

  2. generator 函数

    可以看做一个状态机, 生成的是一个迭代器对象, 可以用来遍历状态机里面的各种状态 创建方式 在函数名前面添加 * , 内部使用 yeild 来标注状态 特性 yield 只能在 generator 中 ...

  3. HDU 2031 进制转换(10进制转R进制)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. ECS centos6.8系统下从nginx安装到简单网站上线配置操作的完整记录

    1.准备工作 1.1已购买阿里云云服务器ECS 1.2域名已购买并解析成功 1.3安装有远程链接工具Xshell和文件传输工具Xftf,并链接上ECS实例 2.安装nginx(在Xshell操作) 2 ...

  5. Oracle恢复误删数据

    1.先查出被删除的时间点: select * from flashback_transaction_query where table_name='表名'; 2.根据时间点恢复数据: insert i ...

  6. iOS之创建通知、发送通知和移除通知的坑

    1.创建通知,最好在viewDidLoad的方法中创建 - (void)viewDidLoad { [super viewDidLoad]; //创建通知 [[NSNotificationCenter ...

  7. POJ 3528--Ultimate Weapon(三维凸包)

    Ultimate Weapon Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 2430   Accepted: 1173 ...

  8. 支付宝支付示例-python

    项目演示: 1.输入金额 ​ 2.扫码支付: ​ 3.支付完成: ​ ​ 具体操作步骤: 第一步:注册账号 https://openhome.alipay.com/platform/appDaily. ...

  9. 10种简单的Java性能优化

    你是否正打算优化hashCode()方法?是否想要绕开正则表达式?Lukas Eder介绍了很多简单方便的性能优化小贴士以及扩展程序性能的技巧. 最近“全网域(Web Scale)”一词被炒得火热,人 ...

  10. apache上.htaccess转向nginx上配置.htaccess伪静态规则

    nginx上配置.htaccess伪静态规则 在apache上.htaccess转向,只要apache编译的时候指明支持rewrite模块即可. 但是换到nginx上方法会有不同,有人说把.htacc ...