#!/usr/bin/python3
import os
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header def main(): sender='1932390299@qq.com'
receiverList=['1932390299@qq.com','1148750911@qq.com']
user='1932390299@qq.com'
emailPwd='gyuagsqxsnonhbhd' #授权码开启
smtpServer='smtp.qq.com'
commonPort=465
emailTitle='Hello,World!'
htmlPath=r'F:/eclipse/readme/readme_eclipse.html'
attachPathList=[r'C:\Users\Administrator\PycharmProjects\Supro\src\logs\Info\20190328.log']
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:
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) # ssl 协议安全发送
smtp=smtplib.SMTP_SSL(host=smtpServer,port=commonPort)
try: 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 ssl模式邮件发送与附件添加的更多相关文章

  1. java mail邮件发送(带附件) 支持SSL

    java mail邮件发送(带附件)有三个类 MailSenderInfo.java package mail; import java.util.Properties; import java.ut ...

  2. C# - VS2019WinFrm程序通过SMTP方式实现邮件发送

    前言 本篇主要记录:VS2019 WinFrm桌面应用程序通过SMTP方式实现邮件发送.作为Delphi转C#的关键一步,接下来将逐步实现Delphi中常用到的功能. 准备工作 搭建WinFrm前台界 ...

  3. C# 通过smtp服务器进行邮件发送 MailHelper

    C# 通过smtp服务器进行邮件发送 MailHelper.cs using System; using System.Data; using System.Configuration; using ...

  4. Laravel5.5 邮件驱动使用 SMTP 驱动实现邮件发送

    laravel5.5 邮件驱动 Laravel 支持多种邮件驱动,包括 smtp.Mailgun.Maildrill.Amazon SES.mail 和 sendmail.Mailgun . Mail ...

  5. System.Net.Mail邮件发送抄送附件(多个)

    /// <summary> /// 邮件发送抄送附件 /// </summary> /// <param name="mailTo">收件人(可 ...

  6. Spring的javaMail邮件发送(带附件)

    项目中经常用到邮件功能,在这里简单的做一下笔记,方便日后温习. 首先需要在配置文件jdbc.properties添加: #------------ Mail ------------ mail.smt ...

  7. C# 解决 邮件发送Excel附件后,excel处于锁定状态

    当使用c#自带的MailMessage类发送excel附件时,再次打开excel会提示处于锁定状态. 解决思路:Attachment是添加附件的类,邮件发送后没有释放该类 public string ...

  8. C#邮件发送(含附件)

    class SendEmail { static void Main(string[] args) { string from = "发件人@yingu.com"; string ...

  9. 用WP SMTP插件实现邮件发送功能

    WordPress本身是采用mail()函数发邮件的,但是这样发出的邮件很容易被放入垃圾箱,很多主机商(特别是Windows主机)为了避免用户滥发邮件直接禁用了mail()函数,还有些云计算平台(比如 ...

随机推荐

  1. yii 修改模块使用的布局文件

    方法一:yii模块默认使用系统当前的主题布局文件,如果在主配置文件中配置了主题比如: 'theme'=>'mythm', 那么yii的模块就使用 protected/themes/mythm/v ...

  2. 让iframe可编辑

    function EnableEdit() { var editor; editor = document.getElementById("HtmlEdit").contentWi ...

  3. 前台提交数据(表单数据、Json数据及上传文件)的类型

    MIME (Multipurpose Internet Mail Extensions) 是描述内容类型的互联网标准.Clients use this content type or media ty ...

  4. 爬虫必备—scrapy-redis(分布式爬虫)

    转载自:http://www.cnblogs.com/wupeiqi/articles/6912807.html scrapy-redis是一个基于redis的scrapy组件,通过它可以快速实现简单 ...

  5. Git——克隆部分文件

    在进行项目开发的时候,有时候会有这样的需求那就是:我们只希望从Git仓库里取指定的文件或者文件夹出来.在SVN里面,这非常容易实现,因为SVN基于文件方式存储,而Git却是基于元数据方式分布式存储文件 ...

  6. c++之stringstream类的用法

    简介: 今天利用opecv提取每一帧图片并保存到本地指定目录下的时,对于保存的每一帧的图片希望第几帧体现在图片名中, 这里便用到了stringstream类的将数字转化为字符串这一功能 C++ Str ...

  7. 网络I/O模型--02阻塞模式(多线程)

    当服务器收到客户端 X 的请求后(读取到所有请求数据后),将这个请求送入一个独立线程进行处理,然后主线程继续接收客户端 Y 的请求. 客户端一侧也可以使用一个子线程和服务器端进行通信.这样客户端主线程 ...

  8. 如何从 GitHub 上下载单个文件夹

    DownGit 好用记得回来点赞(建议***)

  9. url override implements session

    url 重写实现会话概述 URL重写是对GET请求参数的应用,当服务器响应浏览器上一次请求时,将某些相关信息以超链接方式响应给浏览器,超链接中包括请求参数信息. 特点:URL必须以GET方式发送请求. ...

  10. Eclipse4.6安装Tomcat插件时报错:Unable to read repository at http://tomcatplugin.sf.net/update/content.xml. Received fatal alert: handshake_failure

    错误如下: Unable to read repository at http://tomcatplugin.sf.net/update/content.xml.Received fatal aler ...