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

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

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

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

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

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产亚洲视频在线播放大全 | 国产亚洲精彩视频 | 久久经典免费视频 | 日本一级毛片中文字幕 | 天堂色网站 | 99视频精品全国免费 | 9久re在线观看视频精品 | 国产欧美视频综合二区 | 国产精品男人的天堂 | 一级国产精品一级国产精品片 | 成年男女免费视频 | 国产一级片大全 | 久久视奸| 国产91在线 | 亚洲 | 一级做a爰片久久毛片看看 一级做a爰片久久毛片鸭王 | 全免费a级毛片免费毛视频 全午夜免费一级毛片 | 天天看有黄有色大片 | 一级毛片免费播放视频 | 日韩 欧美 中文 亚洲 高清 在线 | 国产成人亚洲精品影院 | 韩国激情啪啪 | 日韩a毛片免费全部播放完整 | 国产一区二区福利久久 | 亚洲综合视频在线观看 | 中国一级做a爰片久久毛片 中日韩欧美一级毛片 | 夜色福利久久久久久777777 | 99国产精品久久久久久久成人热 | 久久久久久久久久久视频国内精品视频 | 免费人成网站免费看视频 | 午夜爽 | 国产精品视频久久 | 日本免费一区二区三区三州 | 一及毛片| 日本精高清区一 | 国产成人a福利在线观看 | 国产高清一级毛片在线不卡 | 免费一级a毛片免费观看欧美大片 | 国产成人精品免费视 | 日韩欧美久久一区二区 | 真人一级毛片国产 | 欧美精品videos|