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

您的位置:首頁技術(shù)文章
文章詳情頁

Python基于smtplib模塊發(fā)送郵件代碼實例

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

smtplib模塊負(fù)責(zé)發(fā)送郵件:是一個發(fā)送郵件的動作,連接郵箱服務(wù)器,登錄郵箱,發(fā)送郵件(有發(fā)件人,收信人,郵件內(nèi)容)。

email模塊負(fù)責(zé)構(gòu)造郵件:指的是郵箱頁面顯示的一些構(gòu)造,如發(fā)件人,收件人,主題,正文,附件等。

email模塊下有mime包,mime英文全稱為“Multipurpose Internet Mail Extensions”,即多用途互聯(lián)網(wǎng)郵件擴(kuò)展,是目前互聯(lián)網(wǎng)電子郵件普遍遵循的郵件技術(shù)規(guī)范。

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

import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.header import Header#郵件服務(wù)器信息smtp_server = 'smtp.qq.com'port = 465 # For starttlssender_email = '[email protected]'password='' #get password from mailsetting#發(fā)送郵件信息,可以發(fā)送給多個收件人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)# 郵件正文內(nèi)容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’))# 構(gòu)造附件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)# 構(gòu)造附件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('郵件發(fā)送成功!!!') 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: 無法發(fā)送郵件') print(e)finally: server.quit()

結(jié)果

郵件發(fā)送成功!!!

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

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 中文字幕二区三区 | 久久免费视频精品 | 最新国产美女一区二区三区 | 久久久久久免费一区二区三区 | 成人91| 91欧美亚洲| a级片在线观看视频 | 草草免费视频 | 黄色三级网站免费 | 九九精品99久久久香蕉 | 91久久精品国产91久久性色也 | 台湾三级香港三级经典三在线 | www成人国产在线观看网站 | 日本不卡一区视频 | 中文字幕波多野不卡一区 | caoporen个人免费公开视频 | 日韩理论在线 | α片毛片 | 91精品一区二区三区在线观看 | 日本全黄| 久久久久久久久久免免费精品 | 精品欧美日韩一区二区 | 荡女妇边被c边呻吟久久 | 欧美日韩一区二区三区视频在线观看 | 久久tv免费国产高清 | 国产欧美日韩精品一区二区三区 | 国产高清在线 | 99ri在线精品视频在线播放 | 日韩中文字幕在线亚洲一区 | 不卡无毒免费毛片视频观看 | 亚洲免费视 | 久久99亚洲精品久久久久99 | 国产va精品网站精品网站精品 | 国产精品亚洲欧美日韩一区在线 | 香港全黄一级毛片在线播放 | 成人毛片免费在线观看 | 欧美一级毛片免费高清aa | 国产呦系列免费 | 国产日韩欧美网站 | 国产精品久久影院 | 久久99国产精一区二区三区! |