国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

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

瀏覽:123日期: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 = '12345689@qq.com'password='' #get password from mailsetting#發送郵件信息,可以發送給多個收件人receivers=['12345689@163.com','12345689@qq.com']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 [’12345689@163.com’, ’12345689@qq.com’] successfully.

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

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产成人精品免费视 | 国产精品欧美一区二区三区不卡 | 亚洲国产欧美在线人成 | 亚洲日本一区二区三区高清在线 | 日韩免费观看一级毛片看看 | 波多野结衣中文在线播放 | 国产免费播放一区二区 | 99久久国内精品成人免费 | 日韩精品一区二三区中文 | 中文字幕一区二区三区亚洲精品 | 亚洲国产小视频 | 欧美亚洲欧美区 | 亚洲一区三区 | 久草手机在线 | 国产1000部成人免费视频 | 全部孕妇毛片丰满孕妇孕交 | 亚洲美女视频在线观看 | 一级做性色a爱片久久片 | 久热精品男人的天堂在线视频 | 国产精选一区二区 | a毛片在线观看 | 玖玖精品在线观看 | 日日a.v拍夜夜添久久免费 | 久久久久国产一级毛片高清片 | www.久久综合 | 亚洲精品久久一区二区无卡 | 成人欧美一级毛片免费观看 | 久久91精品国产91久久跳舞 | 久久精品视频91 | 日韩在线观看视频免费 | 成人伊人青草久久综合网 | 国产深夜福利 | 成人免费大片黄在线观看com | 最新99国产成人精品视频免费 | 日韩精品网 | 一本三道a无线码一区v | 手机国产精品一区二区 | 一区二区三区四区免费视频 | 国产高清av在线播放 | 激情丝袜美女视频二区 | 午夜亚洲国产成人不卡在线 |