纯文本:

#!/usr/bin/env python3
#coding: utf-8 import smtplib
from email.mime.text import MIMEText
from email.header import Header sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***' msg=MIMEText(_text="你好",_charset='utf-8')#中文需参数‘utf-8’,单字节字符不需要
msg['Subject'] = Header(subject, 'utf-8')
msg['From']=sender
msg["To"]=receiver
smtp = smtplib.SMTP()
smtp.connect('smtp.exmail.qq.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

 HTML格式:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***' msgRoot = MIMEMultipart()
msgRoot['Subject'] = 'test message' msgText = MIMEText('<b>Some <i>HTML</i> text</b> and an image.<br><img src="cid:image1"><br>good!','html','utf-8')
msgRoot.attach(msgText) fp = open('e:\\1.jpg', 'rb')
msgImage = MIMEImage(fp.read())
fp.close() msgImage.add_header('Content-ID', '<image1>')
msgRoot.attach(msgImage) smtp = smtplib.SMTP()
smtp.connect('smtp.exmail.qq.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()

 附件邮件:

#coding: utf-8    

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage sender = '***'
receiver = '***'
subject = 'python email test'
smtpserver = 'smtp.163.com'
username = '***'
password = '***' msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = 'test message' #构造附件
att = MIMEText(open('h:\\python\\1.jpg', 'rb').read(), 'base64', 'utf-8')
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="1.jpg"'
msgRoot.attach(att) smtp = smtplib.SMTP()
smtp.connect('smtp.163.com')
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()

  

【python】smtp邮件发送的更多相关文章

  1. python SMTP邮件发送(转载)

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

  2. Python SMTP邮件发送

    SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件.HTML邮件以及带附件的邮件. Python对SMTP支持有smtplib和email两个模块: email负责构造邮件 ...

  3. python学习笔记(SMTP邮件发送:带附件)

    博主有段时间没有更新博客了 先整理一个之前整理过的SMTP邮件发送,这次是带附件的功能 #!/usr/bin/env python # -*- coding: utf_8 -*- from email ...

  4. python学习笔记(SMTP邮件发送)

    想着给框架添加邮件发送功能.所以整理下python下邮件发送功能 首先python是支持邮件的发送.内置smtp库.支持发送纯文本.HTML及添加附件的邮件 之后是邮箱.像163.qq.新浪等邮箱默认 ...

  5. Python 基于Python实现邮件发送

    基于Python实现邮件发送   by:授客 QQ:1033553122 测试环境: Python版本:Python 2.7   注:需要修改mimetypes.py文件(该文件可通过文章底部的网盘分 ...

  6. 用Python实现邮件发送Hive明细数据

    代码地址如下:http://www.demodashi.com/demo/12673.html 一.需求描述 客户需要每周周一接收特定的活动数据,生成Excel或是CSV文件,并通过邮件发送给指定接收 ...

  7. pyqt5实现SMTP邮件发送

    # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'SMTP.ui' # # Created b ...

  8. Python SMTP邮件模块

    SMTP是发送邮件的协议,Python内置对SMTP的支持,可以发送纯文本邮件.HTML邮件以及带附件的邮件. Python对SMTP支持有smtplib和email两个模块,email负责构造邮件, ...

  9. python实现邮件发送完整代码(带附件发送方式)

    实例一:利用SMTP与EMAIL实现邮件发送,带附件(完整代码) __author__ = 'Administrator'#coding=gb2312 from email.Header import ...

  10. python实现邮件发送

    实例补充: #**************************利用STMP自动发送邮件******************************import smtplibsmtp = smtp ...

随机推荐

  1. js 打印软件 Lodop

    官网首页:http://www.c-lodop.com/index.html 下载页面里有使用手册可下载.

  2. 20145322何志威《网络对抗》逆向及Bof基础

    20145322何志威<网络对抗>逆向及Bof基础 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任 ...

  3. 20145311 《Java程序设计》第六周学习总结

    20145311 <Java程序设计>第六周学习总结 教材学习内容总结 第十章(Input&&Output) 10.1InputStream OutputStream 10 ...

  4. ThinkPHP开发博客系统笔记之一

    1.前后台搭建 开发的第一步是搭建前后台系统.搭建前台系统的时候新建了LoginController控制器和登录界面View/Login/index.tpl.模板文件中需要引入js和css文件,这里想 ...

  5. Jwt访问api提示401错误 Authorization has been denied for this request

    教程  http://bitoftech.net/2015/02/16/implement-oauth-json-web-tokens-authentication-in-asp-net-web-ap ...

  6. 上海仪电Azure Stack技术深入浅出系列2:Azure Stack与Azure的有QoS保证的网络联通实现方法和对比测试

    本篇文章作为<Azure Stack技术深入浅出系列>的第二篇,将描述我们目前在构建基于Azure Stack混合云业务解决方案方面所面临的网络连通困难,以及相关技术人员为解决这一问题所做 ...

  7. 【Docker】Windows下docker环境搭建及解决使用非官方终端时的连接问题

    背景 时常有容器方面的需求,经常构建调试导致测试环境有些混乱,所以想在本地构建一套环境,镜像调试稳定后再放到测试环境中. Windows Docker 安装 安装docker toolbox 博主的电 ...

  8. Android------Button 添加声音效果(两种方式)

    我在先前的案例<Android 的底部导航栏 BottomNavigationBar>中添加以底部 的4个按钮切换添加声音 下来看看案例效果图 使用添加依赖 compile 'com.as ...

  9. 51nod-1055-最长等差数列(dp+优化)

    1055 最长等差数列  基准时间限制:2 秒 空间限制:262144 KB 分值: 80 难度:5级算法题  收藏  关注 N个不同的正整数,找出由这些数组成的最长的等差数列.     例如:1 3 ...

  10. rabbitmq之window环境启动

    rabbitmq启动方式有2种 1.以应用方式启动 rabbitmq-server -detached 后台启动 Rabbitmq-server 直接启动,如果你关闭窗口或者需要在改窗口使用其他命令时 ...