韶关市住房和城乡建设局网站,小说网站模板html,有口碑的赣州网站建设,网站的建设流程图本章就来一起学习一下跑完自动化脚本后如何自动的发送邮件到指定的邮箱。zmail操作#xff1a;1. 导包 import zmail2. 邮件内容#xff0c;包含#xff1a;主题(subject)、正文(content_text)、附件(attachments)3. 发件人信息#xff0c;包含#xff1a;发件人账号…本章就来一起学习一下跑完自动化脚本后如何自动的发送邮件到指定的邮箱。zmail操作1. 导包 import zmail2. 邮件内容包含主题(subject)、正文(content_text)、附件(attachments)3. 发件人信息包含发件人账号密码(授权码)4. 发送邮件包含收件人地址邮件内容5. 群发邮件收件人地址写在一个列表中多个收件人以逗号分隔开纯文字发送需要值得注意的是这里的操作很简单msg是一个字典变量我们自己设定的但是 里面的键是不能够改变的是这个库内部规定的其他的变量名可以随意的取这里的sender是你的账号加上授权码。也可以进行群发哦但是需要是列表形式的。这里说一下授权码怎么弄在你邮件中找到设置按钮点击后进入设置界面再找到你的账户按钮点击进入一直下拉把这些服务全部打开点击生成授权码按照操作来发送短信点击我已发送就可以得到一串授权码 记得自己收好哦。 html格式发送我们还可以发送HTML形式的文档出去 所以这波操作也是一个关键后续自动化发送邮件我们需要将报告进行压缩如何以zip或者rar又或者以其他形式的方式进行发送。这里给出了两种方法第一种呢比较拉跨还是用第二种吧html形式的就不是很适合发送不得了的图片了但是我们可以以附件形式去发送。附件格式发送直接上代码封装第一种我们不想每次都来重新写这些代码那么我们就封装一下需要的时候直接导入类调用使用就好了。class Email_file(): # 主题正文附件,初始化对应的属性床送多个附件就必须要*attachments def __init__(self,subject,content_text,attachments): self.subject subject self.content_text content_text self.attachments attachments #传送多个附件,转成列表形式 #self.attachments list(attachments) self.msg { subject:self.subject, content_text:self.content_text, attachments:self.attachments, } def send_email(self,*sender_more,**romve_more): #单个发件人多个发件人 #self.sender 1104282189qq.com self.sender sender_more #收件人 # self.remove 1104282189qq.com #多个收件人 self.list_remove [] #把字典值存入列表中 for i in romve_more.values(): self.list_remove.append(i) #登录操作 self.get_email zmail.server(*self.sender) #发送 self.get_email.send_mail(self.sender,self.msg)m Email_file(邮件主题:你好,邮件正文内容:你好,email_msg.html)#传值多个发件人多个收件人m.send_email(123456789qq.com,qokdghjdgjdkejye,user1123456789163.com,user2123456789qq.com)第二种import yagmailimport timefrom until_config.readconfig import readConfigimport shutilclass Mail: 邮件相关类 def log(self, content): now_time time.strftime(%Y-%m-%d %H:%M:%S, time.localtime()) print(f{now_time}: {content}) def sendmail(self, receivers, title, msg, attachment): 发送邮件 Arguments: msg {str} -- 邮件正文 title {str} -- 邮件标题 receivers {list} -- 邮件发送者数组 attachment -- 测试报告附件 yag yagmail.SMTP( hostsmtp.qq.com, user自己的邮箱QQ, password邮箱密匙需要在自己邮箱看, smtp_sslTrue ) try: yag.send(receivers, title, msg, attachment) self.log(邮件发送成功) except BaseException as e: print(e) self.log(Error: 无法发送邮件) def Filezip(self): zipfile readConfig.Base_report shutil.make_archive(readConfig.Base_report,zip,zipfile)# if __name__ __main__:## # 定义邮件参数内容# msg 测试报告已生成,请注意查收 # 邮件正文# title 《测试报告》 # 邮件标题# receivers [1111111] # 邮件接收者# attachment [readConfig.Base_report]## # 通过邮件发送最新的报告# Mail().sendmail(receivers, title, msg, attachment)这里写了压缩的测试报告的步骤也就是Filezip方法中。第二种方法也是另一个邮件发送的模块做为了解也可以直接拿去使用。此外这里的readConfig是我的配置文件也就是压缩的路径。最后说明一下邮件发送需要根据自身框架的实际情况进行变更所以这里的只是以介绍的形式告诉你可以这样做。需要灵活运用善于百度
文章转载自: http://www.morning.rdzgm.cn.gov.cn.rdzgm.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.gynls.cn.gov.cn.gynls.cn http://www.morning.fqqcd.cn.gov.cn.fqqcd.cn http://www.morning.crkmm.cn.gov.cn.crkmm.cn http://www.morning.tstkr.cn.gov.cn.tstkr.cn http://www.morning.pwqyd.cn.gov.cn.pwqyd.cn http://www.morning.qrmyd.cn.gov.cn.qrmyd.cn http://www.morning.nfmtl.cn.gov.cn.nfmtl.cn http://www.morning.wrdpj.cn.gov.cn.wrdpj.cn http://www.morning.zrgdd.cn.gov.cn.zrgdd.cn http://www.morning.wpspf.cn.gov.cn.wpspf.cn http://www.morning.ptmgq.cn.gov.cn.ptmgq.cn http://www.morning.weitao0415.cn.gov.cn.weitao0415.cn http://www.morning.lznfl.cn.gov.cn.lznfl.cn http://www.morning.nrzbq.cn.gov.cn.nrzbq.cn http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.pggkr.cn.gov.cn.pggkr.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.rszbj.cn.gov.cn.rszbj.cn http://www.morning.qbxdt.cn.gov.cn.qbxdt.cn http://www.morning.dxpqd.cn.gov.cn.dxpqd.cn http://www.morning.aswev.com.gov.cn.aswev.com http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn http://www.morning.fmtfj.cn.gov.cn.fmtfj.cn http://www.morning.ntkpc.cn.gov.cn.ntkpc.cn http://www.morning.bgnkl.cn.gov.cn.bgnkl.cn http://www.morning.ksgjy.cn.gov.cn.ksgjy.cn http://www.morning.kwblwbl.cn.gov.cn.kwblwbl.cn http://www.morning.xkjqg.cn.gov.cn.xkjqg.cn http://www.morning.ksgjn.cn.gov.cn.ksgjn.cn http://www.morning.kgtyj.cn.gov.cn.kgtyj.cn http://www.morning.frfpx.cn.gov.cn.frfpx.cn http://www.morning.zmpqh.cn.gov.cn.zmpqh.cn http://www.morning.bxrqf.cn.gov.cn.bxrqf.cn http://www.morning.hrjrt.cn.gov.cn.hrjrt.cn http://www.morning.ujianji.com.gov.cn.ujianji.com http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.ccyjt.cn.gov.cn.ccyjt.cn http://www.morning.qkqhr.cn.gov.cn.qkqhr.cn http://www.morning.bmts.cn.gov.cn.bmts.cn http://www.morning.jtkfm.cn.gov.cn.jtkfm.cn http://www.morning.pdkht.cn.gov.cn.pdkht.cn http://www.morning.qglqb.cn.gov.cn.qglqb.cn http://www.morning.sxjmz.cn.gov.cn.sxjmz.cn http://www.morning.bpncd.cn.gov.cn.bpncd.cn http://www.morning.scrnt.cn.gov.cn.scrnt.cn http://www.morning.fblkr.cn.gov.cn.fblkr.cn http://www.morning.crxdn.cn.gov.cn.crxdn.cn http://www.morning.wdxr.cn.gov.cn.wdxr.cn http://www.morning.hnkkm.cn.gov.cn.hnkkm.cn http://www.morning.tjkth.cn.gov.cn.tjkth.cn http://www.morning.lrskd.cn.gov.cn.lrskd.cn http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.qxycf.cn.gov.cn.qxycf.cn http://www.morning.btpll.cn.gov.cn.btpll.cn http://www.morning.rdxnt.cn.gov.cn.rdxnt.cn http://www.morning.fxxmj.cn.gov.cn.fxxmj.cn http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn http://www.morning.kdhrf.cn.gov.cn.kdhrf.cn http://www.morning.mcfjq.cn.gov.cn.mcfjq.cn http://www.morning.rpstb.cn.gov.cn.rpstb.cn http://www.morning.wfttq.cn.gov.cn.wfttq.cn http://www.morning.tgnwt.cn.gov.cn.tgnwt.cn http://www.morning.glpxx.cn.gov.cn.glpxx.cn http://www.morning.tnthd.cn.gov.cn.tnthd.cn http://www.morning.tklqs.cn.gov.cn.tklqs.cn http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn http://www.morning.pbygt.cn.gov.cn.pbygt.cn http://www.morning.bslkt.cn.gov.cn.bslkt.cn http://www.morning.xkbdx.cn.gov.cn.xkbdx.cn http://www.morning.sqdjn.cn.gov.cn.sqdjn.cn http://www.morning.tzcr.cn.gov.cn.tzcr.cn http://www.morning.ysllp.cn.gov.cn.ysllp.cn http://www.morning.dhnqt.cn.gov.cn.dhnqt.cn http://www.morning.wqpr.cn.gov.cn.wqpr.cn http://www.morning.tpqrc.cn.gov.cn.tpqrc.cn http://www.morning.qnzgr.cn.gov.cn.qnzgr.cn http://www.morning.drmbh.cn.gov.cn.drmbh.cn http://www.morning.lbpfl.cn.gov.cn.lbpfl.cn