亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python3通過qq郵箱發(fā)送郵件以及附件

 更新時(shí)間:2020年05月20日 15:48:03   作者:打鹵  
這篇文章主要為大家詳細(xì)介紹了python3通過qq郵箱發(fā)送郵件以及附件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python3通過qq郵箱發(fā)送郵件以及附件的具體代碼,供大家參考,具體內(nèi)容如下

開啟qq郵箱的smtp服務(wù)

代碼:

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'  # 郵箱服務(wù)器
 mail_user = 'dalu@qq.com' # 發(fā)件人郵箱密碼(當(dāng)時(shí)申請smtp給的口令)
 mail_pwd = '***********' # SMTP密碼
 s = smtplib.SMTP_SSL(mail_host, 465,timeout=5)
 s.login(mail_user, mail_pwd)
 #郵件內(nèi)容
 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('發(fā)送成功')
 except Exception as e:
  print(e)

to_list = [
 #多用戶使用的list
 'dalu@qq.com',
]

Mailer(to_list,th1="這是要發(fā)的郵件內(nèi)容",Subject='郵件標(biāo)題',unipath=r'F:\test.xlsx')

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論