#!/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. Modify Dokuwiki Email Template 修改 Dokuwiki 邮件模板

    Email Notification Templates   There are two places to modify 1) log in as Admin -> configuration ...

  2. c#实现内存映射文件共享内存

    原文:http://blog.csdn.net/wangtiewei/article/details/51112668 内存映射文件是利用虚拟内存把文件映射到进程的地址空间中去,在此之后进程操作文件, ...

  3. Progress数据库配置与应用

    创建database 开始->程序->OpenEdge,选择:Desktop,进行database创建. 选择创建一个空database或直接copy一个demo的database,我们选 ...

  4. mysql 命令行查看数据库、创建数据库、选择数据库、删除数据库

    mysql数据库命名规则(标识符规则): 不能和已存在的命名重名: 由大小写字母.数据.下划线.@.# 和 $ 符号组成: 首字母不能是数字和$符. 不允许有空格和特殊字符. 不允许是mysql的保留 ...

  5. Oracle数据库通过DBLINK实现远程访问

    什么是DBLINK? dblink(Database Link)数据库链接顾名思义就是数据库的链接  ,就像电话线一样,是一个通道,当我们要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中就 ...

  6. Webservice和EJB

    WebService Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯 ...

  7. LeetCode 题解之Find Peak Element

    1.题目描述 2.题目分析 在数组的首尾各加入INT_MIN ,然后遍历数组. 3.代码 int findPeakElement(vector<int>& nums) { ) ; ...

  8. 自己搭建anki服务器

    目录 centos端 电脑客户端 安卓端 centos端 # 安装服务 yum -y install python-setuptools easy_install Ankiserver mkdir - ...

  9. 使用 PowerShell 创建 Linux 虚拟机

    Azure PowerShell 模块用于从 PowerShell 命令行或脚本创建和管理 Azure 资源. 本指南详细介绍了如何使用 Azure PowerShell 模块部署运行 Ubuntu ...

  10. Vue2学习笔记:v-for指令

    1.使用 <!DOCTYPE html> <html> <head> <title></title> <meta charset=&q ...