smtp ssl模式邮件发送与附件添加
#!/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模式邮件发送与附件添加的更多相关文章
- java mail邮件发送(带附件) 支持SSL
java mail邮件发送(带附件)有三个类 MailSenderInfo.java package mail; import java.util.Properties; import java.ut ...
- C# - VS2019WinFrm程序通过SMTP方式实现邮件发送
前言 本篇主要记录:VS2019 WinFrm桌面应用程序通过SMTP方式实现邮件发送.作为Delphi转C#的关键一步,接下来将逐步实现Delphi中常用到的功能. 准备工作 搭建WinFrm前台界 ...
- C# 通过smtp服务器进行邮件发送 MailHelper
C# 通过smtp服务器进行邮件发送 MailHelper.cs using System; using System.Data; using System.Configuration; using ...
- Laravel5.5 邮件驱动使用 SMTP 驱动实现邮件发送
laravel5.5 邮件驱动 Laravel 支持多种邮件驱动,包括 smtp.Mailgun.Maildrill.Amazon SES.mail 和 sendmail.Mailgun . Mail ...
- System.Net.Mail邮件发送抄送附件(多个)
/// <summary> /// 邮件发送抄送附件 /// </summary> /// <param name="mailTo">收件人(可 ...
- Spring的javaMail邮件发送(带附件)
项目中经常用到邮件功能,在这里简单的做一下笔记,方便日后温习. 首先需要在配置文件jdbc.properties添加: #------------ Mail ------------ mail.smt ...
- C# 解决 邮件发送Excel附件后,excel处于锁定状态
当使用c#自带的MailMessage类发送excel附件时,再次打开excel会提示处于锁定状态. 解决思路:Attachment是添加附件的类,邮件发送后没有释放该类 public string ...
- C#邮件发送(含附件)
class SendEmail { static void Main(string[] args) { string from = "发件人@yingu.com"; string ...
- 用WP SMTP插件实现邮件发送功能
WordPress本身是采用mail()函数发邮件的,但是这样发出的邮件很容易被放入垃圾箱,很多主机商(特别是Windows主机)为了避免用户滥发邮件直接禁用了mail()函数,还有些云计算平台(比如 ...
随机推荐
- CodeForces760A
A. Petr and a calendar time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- wamp 安装monggo扩展
1.下载对应的monggo扩展 http://pecl.php.net/package/mongo 2. 找对应的版本 放在D:\program\wamp\bin\php\php5.5.12\ext ...
- BZOJ4566: [Haoi2016]找相同字符(后缀自动机)
题意 题目链接 Sol 直接在SAM上乱搞 枚举前缀,用SAM统计可以匹配的后缀,具体在匹配的时候维护和当前节点能匹配的最大值 然后再把parent树上的点的贡献也统计上,这部分可以爆跳parent树 ...
- 【代码笔记】iOS-cell折叠
一,效果图. 二,工程图. 三,代码. AppDelegate.h #import <UIKit/UIKit.h> //加入头文件 #import "myQQView.h&quo ...
- css绘制进度条,持续转动的进度条
//只有 progress pregress-par bar,进度条不会转, //增加 active 这个类,进度条会转, //html结构 <div class='progress activ ...
- html打造动画【系列2】- 可爱的蛙蛙表情
先感受一下全部表情包: 在开始之前先安利一个知识点:Flex弹性布局 我们一般做水平三列布局都是用的float方法,将每一块浮动显示在同一行.这种方法会导致元素没有原来的高度属性,要用清除浮动来解决空 ...
- android studio *.apk does not exist on disk
Build -> Clean Project Restart Android Studio
- Phoenix介绍(持续更新)
现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要记录Phoenix. phoenix,中文译为“凤凰”,很美的名字.Phoenix是 ...
- Oracle数据库通过DBLINK实现远程访问
什么是DBLINK? dblink(Database Link)数据库链接顾名思义就是数据库的链接 ,就像电话线一样,是一个通道,当我们要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中就 ...
- 梯度下降法实现最简单线性回归问题python实现
梯度下降法是非常常见的优化方法,在神经网络的深度学习中更是必会方法,但是直接从深度学习去实现,会比较复杂.本文试图使用梯度下降来优化最简单的LSR线性回归问题,作为进一步学习的基础. import n ...