1.非ssl发送:

授权码机制,开启smtp,获取授权码以qq邮箱为例:

附件展示:

#!/usr/bin/python3
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email.mime.image import MIMEImage def main(): sender='1932390299@qq.com'
receiverList=['1932390299@qq.com']
user='1932390299@qq.com'
emailPwd='gyuagsqxsnonhbhd' #用需开通授权码
smtpServer='smtp.qq.com'
commonPort=25
emailTitle='Hello,World!'
htmlPath=r'F:/eclipse/readme/readme_eclipse.html'
attachPathList=[r'C:\Users\Administrator\PycharmProjects\Supro\src\logs\Info\20190330.log',r'C:\Users\Administrator\PycharmProjects\Supro\src\logs\Info\testpc.png']
emailChanel(sender,receiverList,user,emailPwd,smtpServer,commonPort,emailTitle,htmlPath,attachPathList) def emailChanel(sender,receiverList,user,emailPwd,smtpServer,commonPort,emailTitle,htmlPath=None,attachPathList=None):
multiPart=MIMEMultipart()
multiPart['From']=sender
multiPart['To']=','.join(receiverList)
subject=emailTitle
multiPart['Subject']=Header(subject,"utf-8")
if os.path.isfile(htmlPath):
if os.path.exists(htmlPath):
pass
else:
raise IOError("htmlPath not exist")
else:
raise IOError("html path is not file..")
emailBody=MIMEText(_text=open(htmlPath,'rb').read(),_subtype='html',_charset="utf-8")
multiPart.attach(emailBody)
if isinstance(attachPathList,list):
for attachPath in attachPathList:
if os.path.exists(attachPath):
pass
else:
raise IOError("attachPath not exist")
else:
raise TypeError("expected type is list,but get {}".format(type(attachPathList).__name__))
for attachPath in attachPathList:
if os.path.splitext(attachPath)[-1]==".log":
attach=MIMEText(open(attachPath, 'rb').read(), 'base64', 'utf-8')
attach["Content-Type"] = 'application/octet-stream'
attach["Content-Disposition"] = 'attachment; filename="dailyLog.log"' # filename not strict
multiPart.attach(attach)
if os.path.splitext(attachPath)[-1]==".png":
fp = open(attachPath, 'rb')
msgImage = MIMEImage(fp.read(),_subtype='octet-stream')
fp.close()
msgImage.add_header('Content-Disposition', 'attachment', filename="attach.png")
multiPart.attach(msgImage)
smtp=smtplib.SMTP(timeout=30)
try:
smtp.connect(host=smtpServer,port=commonPort)
smtp.login(user,emailPwd)
smtp.sendmail(sender,receiverList,multiPart.as_string())
except smtplib.SMTPException as e:
print("send fail",e)
else:
print("success")
finally:
try:
smtp.quit()
except smtplib.SMTPException:
print("quit fail")
else:
print("quit success")
if __name__ == '__main__':
main()

  

smtp发送html报告与日志附件图片png的更多相关文章

  1. jenkins+ant+jmeter html报告文件作为附件发送(ant-jmeter支持javamail)

    前言:由于ant-jmeter目前的版本不支持javamail,也就是说发送邮件时只能借助jenkins自带的发送邮件插件来发送报告. 但是jenkins发送邮件支持发送邮件内容(且有价值.有营养的内 ...

  2. centos7安装Logwatch配合msmtp邮件客户端发送服务器监控分析日志

    ########################### #DATE 2016-07-29                         # #Authur by Denilas Yeung     ...

  3. .Net Mail SMTP 发送网络邮件

    刚刚迈入"开发"的行列 一直有一个想法 我什么时候能给我庞大的用户信息数据库给每一位用户邮箱发送推荐信息呢? 刚迈入"编程两个月的时间" 我采用 SMTP 发送 ...

  4. SMTP邮件传输协议发送邮件和附件

    在以前接触的项目中,一直都是在做网站时用到了发送mail 的功能,在asp 和.net 中都有相关的发送mail 的类, 实现起来非常简单.最近这段时间因工作需要在C++ 中使用发送mail 的功能, ...

  5. SMTP邮件传输协议发送邮件和附件(转)

    1.     SMTP 常用命令简介 1). SMTP 常用命令 HELO/EHLO 向服务器标识用户身份 MAIL 初始化邮件传输 mail from: RCPT 标识单个的邮件接收人:常在MAIL ...

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

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

  7. 在Delphi中使用indy SMTP发送gmail邮件[转]

    在Delphi中使用indy SMTP发送gmail邮件[转] 2012-01-01 22:44:30|  分类: Delphi |  标签: |举报 |字号大中小 订阅     在Delphi中发送 ...

  8. 个性化设置phpMyAdmin,去掉“以树形显示数据库”,禁用“发送错误报告”

    个性化设置phpMyAdmin 在使用phpMyAdmin 3.5.8.2时,发现: 如果数据库有相同的前缀,左边数据库导航会把前缀合并,即所谓的“以树形显示数据库”,真的有点不习惯,如下图所示: 不 ...

  9. [原]Jenkins(八)---jenkins构建项目报错时发送错误报告邮件

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/533 ...

随机推荐

  1. 总结oninput、onchange与onpropertychange事件的使用方法和差别

    onchange事件仅仅在键盘或者鼠标操作改变对象属性,且失去焦点时触发,脚本触发无效:而onkeydown/onkeypress/onkeyup在处理复制.粘贴.拖拽.长按键(按住键盘不放)等细节上 ...

  2. navicat 批量插入 测试数据

    1. 前言 遇到线上大sql执行较慢, 10s+, 做优化改进时,首先想到的是在本地造出一个类似的库环境,先本地实验. 然后往表中创建大量数据... 2. 方案 利用mysql函数来插入大量数据 代码 ...

  3. mysql 免安装版

    通过MySQL安装程序(.msi文件)来安装虽然简洁高效,但不够灵活,所以我们这里介绍免安装版. 1.  下载: 进入官网-->Downloads-->Community(社区版)--&g ...

  4. 聊聊 getClientRects 和 getBoundingClientRect 方法

    开始表演 今天来聊一下两个相似的方法,它们就是:getBoundingClientRect().getClientRects(). 只见它们俩手拉手地登上了舞台,一个鞠躬,便开始滔滔不绝起来. 自述 ...

  5. LeetCode题解之Add Strings

    1.题目描述 2.问题分析 直接按照加法运算规则运算即可,注意进位问题. 3.代码 string addStrings(string num1, string num2) { if( num1.emp ...

  6. 1.Junit test使用

    1.导入maven依赖 <dependency> <groupId>junit</groupId> <artifactId>junit</arti ...

  7. inline-flex值的含义

    css中, flex设置在container中,默认情况下占用全部空间,但是如果使用inline-flex值,则container具有inline-block元素的某种特点,只占用需要的宽度

  8. Oracle 数据库执行慢SQL

    ) hou, - ))) mini, c.sql_address, c.inst_id,f.full_name,u.user_name, b.user_concurrent_program_name, ...

  9. Jenkins操作,实现增删改查

    Jenkins的版本是:Jenkins2.138.1 实现的操作接口: using System; using System.Collections.Generic; namespace iHRPub ...

  10. JavaScript运行机制的学习

    今天在偶然在网上看到一个JavaScript的面试题,尝试着看了一下,很正常的就做错了,然后给我们前端做,哈哈,他居然也顺理成章做的错了,代码大概是这样的 /*1 下面代码会怎样执行?执行结果是什么* ...