python中怎么使用yagmail发送邮件功能(python,yagmail,开发技术)

时间:2024-05-01 11:01:41 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

1.使用前先要安装 yagmail

2.使用QQ邮箱发送邮件,使用的是授权码,需要先到QQ邮箱申请授权码。

邮箱设置-->账户

python中怎么使用yagmail发送邮件功能

3.yagmail 模块发送邮件更加简单,四行代码

#-*-encoding:utf-8-*-importyagmaildefE_mali_jj(fr,key,etype,text,to,attachments):''':paramfr:发送邮箱:paramkey:授权码:parametype:邮件类型:paramtext:文本:paramto:接受邮箱:paramattachments:附件文件地址,空则填'':return:'''  #链接邮箱服务器yag=yagmail.SMTP(user=fr,password=key,host=etype)#邮箱正文contents=[text]#发送邮件yag.send(to=to,subject='邮件标题',contents=contents,attachments=attachments)#subject标题yag.close()print("邮件发送成功")if__name__=='__main__':E_mali_jj("123456@qq.com","gwheybuaamrqbihh",'smtp.qq.com',"邮件正文内容","123456@qq.com","E:\\proto_code\\Roshan-01-microscript-proto_test-master-src\\src\\report\\report.html")

邮件发送给多个人,将接受的邮箱放在列表中即可

#发送邮件yag.send(to=['123456@qq.com','678910@qq.com','10111213@qq.com'],subject='subject',contents=contents,attachments="")

4.发送邮件带附件

#-*-coding:utf-8-*-importyagmailyag=yagmail.SMTP(user="157540957@qq.com",password="kayzilfyziulbhbb1",host='smtp.qq.com')"""user:发送的邮箱password:授权码"""#邮箱正文contents=['测试发送邮件']#附件attachments="D:\\code\\0906\\api_test009\\report\\report.html"#发送邮件try:yag.send(to='3437871062@qq.com',subject='subject',contents=contents,attachments=attachments)exceptExceptionase:print("Error:抱歉!发送邮件失败。",e)"""to:接收者subject:邮件主题contents:正文attachments:附件"""yag.close()

5.封装

#-*-coding:utf-8-*-importyagmaildefsend(user,password,receiver):yag=yagmail.SMTP(user=user,password=password,host='smtp.qq.com')"""user:发送的邮箱password:授权码"""#邮箱正文contents=['测试发送邮件']#附件attachments="D:\\code\\0906\\api_test009\\report\\report.html"#发送邮件try:yag.send(to=receiver,subject='subject',contents=contents,attachments=attachments)exceptExceptionase:print("Error:抱歉!发送邮件失败。",e)"""to:接收者subject:邮件主题contents:正文attachments:附件"""yag.close()if__name__=='__main__':send("123456@qq.com","kayzilfyziulbhbb1","45678910@qq.com")
 </div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
本文:python中怎么使用yagmail发送邮件功能的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:html中ol标签怎么用下一篇:

4 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18