import  smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
"""多用户及带附件发送邮件代码""" smtpserver = 'smtp.163.com' #发送邮箱服务器 user = '***@163.com'
password = '密码' sender = 'a5974939632@163.com'
receive = ['接收邮箱1', '接收邮箱2'] subject = 'Web Selenium 自动化测试报告'
content = '<html><h1 style="color:red">我要自学网,自学成才!</h1></html>' send_file = open(r'E:\study\SeleniumPython\UnitTest\Test_Baidu\test_report\2019-01-08 12_00_24result.html','rb').read() att = MIMEText(send_file, 'base64', 'utf-8')
att['Content-Type'] = 'application/octet-stream'
att['Content-Disposition'] = 'attachment:filename="2019-01-08 12_00_24result.html"' msgRoot = MIMEMultipart()
msgRoot.attach(MIMEText(content, 'html', 'utf-8'))
msgRoot['Subject'] = subject
msgRoot['From'] = sender
msgRoot['To'] = ','.join(receive)
msgRoot.attach(att) smtp = smtplib.SMTP_SSL(smtpserver,465)
smtp.helo(smtpserver)
smtp.ehlo(smtpserver)
smtp.login(user,password) print("start send Email...")
smtp.sendmail(sender,receive,msgRoot.as_string())
smtp.quit()
print("send email end!")

用python SMTP进行邮件发送的更多相关文章

  1. python自动化之邮件发送

    #!/usr/bin/env python # -*- coding:utf-8 -*- import smtplib from email.mime.multipart import MIMEMul ...

  2. python smtp 发邮件 添加附件

    # -*- coding:utf-8 -*- # __author__ = 'justing' import os import smtplib from email.mime.multipart i ...

  3. python SMTP发邮件

    # from email.mime.text import MIMEText from email.header import Header import smtplib # sender = 'zc ...

  4. Selenium+Python之163邮件发送

    今晚写了一个163邮箱登录的脚本,由于不停的访问163登录主页导致直接访问163邮箱主页登录需要输入验证码,因为无法获取到验证码,就这导致直接访问主页登录脚本不可行,为了绕过验证码,现在先访问hao1 ...

  5. smtp outlook邮件发送非授权码模式

    1.起因:send fail SMTP AUTH extension not supported by server. 使用端口25 和587均失效出现此问题 首先前往outlook修改设置pop和I ...

  6. python smtp发邮件报错“[Errno -2] Name or service not known”的解决

    最近给ss-py-mu写了个检查用户是否到期,并在到期前的第2天邮件提醒的功能. 配置存储在ini文件中,通过configparser模块获取,但尝试发送邮件的时候发现报错[Errno -2] Nam ...

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

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

  8. JavaUtil smtp 邮件发送

    需要用到的jar包:javax.mail.jar package com.lee.util; import java.io.UnsupportedEncodingException; import j ...

  9. SMTP协议及POP3协议-邮件发送和接收原理(转)

    本文转自https://blog.csdn.net/qq_15646957/article/details/52544099 感谢作者 一. 邮件开发涉及到的一些基本概念 1.1.邮件服务器和电子邮箱 ...

随机推荐

  1. Spring(九)之事件处理

    Spring的核心是ApplicationContext,它管理bean的完整生命周期.ApplicationContext在加载bean时发布某些类型的事件.例如,ContextStartedEve ...

  2. 关于selenium获取token sessionid

    # 获取sessionid def get_sessionid(self): # 是要从localStorage中获取还是要从sessionStorage中获取,具体看目标系统存到哪个中 # wind ...

  3. js获取今天,明天,本周五,下周五日期的函数

    代码比较简单,随便写写 /** * a连接快速选择日期函数 */ function timeChooseSimple(key, me) { //today,tomorrow,thisWeek,next ...

  4. scrapy基础

    scrapy Scrapy 是用 Python 实现的一个为了爬取网站数据.提取结构性数据而编写的应用框架. Scrapy 常应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中. Scrapy ...

  5. PHP-----PHP程序设计基础教程----第四章数组

    4.1 初识数组 4.1.1 什么是数组 数组是一个可以存储一组或者一系列数值的变量.在PHP中,数组中的元素分两部分,分别为键(Key)和值(Value).其中,“键”为元素的识别名称,也被称为数组 ...

  6. Contract Helper

    using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Que ...

  7. asp.net页面刷新或者回发后DIV的滚动条位置不变!(转)

    源文件:http://www.cnblogs.com/nyth/archive/2011/06/10/2077868.html 当把数据放在div里面,然后给div设置Scroll显示,在页面刷新后或 ...

  8. 20155328 实验四 Android程序设计 实验报告

    20155328 实验四 Android程序设计 第24章 初识Android 提交点1:完成HelloWorld并显示自己的学号 安装Android Studio后,创建了属于自己的Project( ...

  9. 最简单的rman操作

    连接: [root@oracle000 ‾]# su - oracle [oracle@oracle000 ‾]$ rman target / lines) Recovery Manager: Rel ...

  10. 【转载】Alpha混合物体的深度排序

    原文:Alpha混合物体的深度排序 先说个题外话, 本来我想解答一下最近Creators Club论坛上经常出现的一个问题, 意外的是在网上竟然找不到什么全面的答案.. 这是个有着复杂答案的简单问题: ...