色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

Python基于smtplib模塊發送郵件代碼實例

瀏覽:93日期:2022-07-24 08:04:16

smtplib模塊負責發送郵件:是一個發送郵件的動作,連接郵箱服務器,登錄郵箱,發送郵件(有發件人,收信人,郵件內容)。

email模塊負責構造郵件:指的是郵箱頁面顯示的一些構造,如發件人,收件人,主題,正文,附件等。

email模塊下有mime包,mime英文全稱為“Multipurpose Internet Mail Extensions”,即多用途互聯網郵件擴展,是目前互聯網電子郵件普遍遵循的郵件技術規范。

該mime包下常用的有三個模塊:text,image,multpart。

import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.header import Header#郵件服務器信息smtp_server = 'smtp.qq.com'port = 465 # For starttlssender_email = '[email protected]'password='' #get password from mailsetting#發送郵件信息,可以發送給多個收件人receivers=['[email protected]','[email protected]']subject='This is import Python SMTP 郵件(文件傳輸) 多媒體測試'# message = MIMEText(text, 'plain', 'utf-8') #文本郵件message = MIMEMultipart()message['Subject'] = Header(subject, 'utf-8')message['from'] = sender_emailmessage['to'] = ','.join(receivers)# 郵件正文內容text='''Dear Sir:how are you ? nfor detail information pls refer to attach1。nThe files you need are as followed.nIf you have any concern pls let me known.nenjoy your weekend.nBEST REGARDS n'''# message.attach(MIMEText(’for detail information pls refer to attach1。n The files you need are as followed. n If you have any concern pls let me known. n enjoy your weekend’, ’plain’, ’utf-8’)message.attach(MIMEText(text,’plain’,’utf-8’))# 構造附件1attach_file1=’IMG1965.JPG’attach1 = MIMEText(open(attach_file1, ’rb’).read(), ’base64’, ’utf-8’)attach1['Content-Type'] = ’application/octet-stream’attach1['Content-Disposition'] = ’attachment; filename={0}’.format(attach_file1)message.attach(attach1)# 構造附件2attach_file2=’YLJ.jpg’attach2 = MIMEText(open(attach_file2, ’rb’).read(), ’base64’, ’utf-8’)attach2['Content-Type'] = ’application/octet-stream’attach2['Content-Disposition'] = ’attachment; filename={0}’.format(attach_file2)message.attach(attach2)# Try to log in to server and send email# server = smtplib.SMTP_SSL(smtp_server,port)server = smtplib.SMTP_SSL(smtp_server,port)try: server.login(sender_email, password) server.sendmail(sender_email,receivers,message.as_string()) print('郵件發送成功!!!') print('Mail with {0} & {1} has been send to {2} successfully.'.format(attach_file1,attach_file2,receivers))except Exception as e: # Print any error messages to stdout print('Error: 無法發送郵件') print(e)finally: server.quit()

結果

郵件發送成功!!!

Mail with IMG1965.JPG & IMG1963.jpg has been send to [’[email protected]’, ’[email protected]’] successfully.

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 亚洲自拍中文 | 日韩不卡一二三区 | 日本三级网站在线线观看 | 94欧美setu | 99在线观看免费视频 | 91国内视频在线观看 | 欧美日韩久久 | 欧美精品亚洲一区二区在线播放 | 韩国日本三级在线观看 | 老司机深夜影院入口aaaa | 天天看有黄有色大片 | 国产区在线免费观看 | 精品一区二区三区免费毛片爱 | 久久影院yy6080| 91av观看| 久久久久久久久一次 | 欧美一级毛片欧美一级无片 | 国产美女主播一级成人毛片 | 一本一道久久综合狠狠老 | 日本欧美高清 | 性欧美videofree另类17 | 一级毛片免费观看不卡的 | 黄色a三级三级三级免费看 黄色a网 | 男人的天堂在线观看入口 | 亚洲欧美日韩在线观看二区 | 色综合天天综合网看在线影院 | 中国国产一级毛片视频 | 一级a毛片免费观看久久精品 | 亚洲国产精品线观看不卡 | 国产99视频在线观看 | 成人午夜久久 | 欧美一级毛片欧美一级 | 给我一个可以看片的www日本 | 国产一区视频在线播放 | 国内一级特黄女人精品片 | 99久女女精品视频在线观看 | 202z欧美成人 | 99精品欧美一区二区三区 | a大片久久爱一级 | 成人黄网18免费观看的网站 | 美女一级毛片免费看看 |