本文实例为大家分享了python3通过qq邮箱发送邮件以及附件的具体代码,供大家参考,具体内容如下
开启qq邮箱的smtp服务
代码:
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def Mailer(to_list,th1=None,Subject=None,unipath=None): mail_host = 'smtp.qq.com' # 邮箱服务器 mail_user = 'dalu@qq.com' # 发件人邮箱密码(当时申请smtp给的口令) mail_pwd = '***********' # SMTP密码 s = smtplib.SMTP_SSL(mail_host, 465,timeout=5) s.login(mail_user, mail_pwd) #邮件内容 mail = str(th1) msg = MIMEMultipart() msgtext = MIMEText(mail.encode('utf8'), _subtype='html', _charset='utf8') msg['From'] = mail_user msg['Subject'] = Subject msg['To'] = ",".join(to_list) if unipath is not None: att1 = MIMEText(open(unipath, 'rb').read(), 'base64', 'gb2312') att1["Content-Type"] = 'application/octet-stream' att1.add_header('Content-Disposition', 'attachment',filename=(Subject+ '.xlsx')) msg.attach(att1) msg.attach(msgtext) try: s.sendmail(mail_user, to_list, msg.as_string()) s.close() print('发送成功') except Exception as e: print(e) to_list = [ #多用户使用的list 'dalu@qq.com', ] Mailer(to_list,th1="这是要发的邮件内容",Subject='邮件标题',unipath=r'F:\test.xlsx')
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 曾轶可.2011-一只猫的旅行【天娱传媒】【WAV+CUE】
- 黑神话悟空上品狼刺客精魄获取方法一览|上品狼刺客精魄收集攻略
- 视觉小说《神椿市建设中REGENERATE》将于2025年2月20日发售
- 黑神话悟空上品鼠弩手精魄获取方法一览|上品鼠弩手精魄收集攻略
- 中国音乐地图听见世界非物质文化遗产《非遗HQCD》wav
- 中国民乐合奏作品集《华夏之音HQ》头版限量编号[WAV+CUE]
- [电影原声带]黎允文《天将雄师》[FLAC+CUE]
- 曝NS继任机型已进入量产阶段:已花了30亿日元
- 不是Switch2?曝《马里奥惊奇》NS捆绑包即将公开
- 暖心任天堂!网友Switch维修返还时贴纸被完好保留
- 《国语老歌 经典对唱情歌 2CD》[WAV/分轨][1.1GB]
- 《刀郎 翻唱精选华语专辑 披着羊皮的狼 》[WAV+CUE][430MB]
- 《真的田震 中国乐坛红极一时的歌者 精品集》[WAV+CUE][300MB]
- 群星.1995-新滚石九大天王之情歌大全【滚石】【WAV+CUE】
- 群星.1993-滚石九大天王十二出好戏·纵夏欢唱【滚石】【WAV+CUE】