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

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

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

瀏覽:127日期: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 編程
相關文章:
主站蜘蛛池模板: 欧美一区二区在线播放 | 亚洲成a人片在线看 | 久草视频2| 91不卡在线精品国产 | 看一级毛片一区二区三区免费 | 欧美人在线一区二区三区 | 日本b站一卡二卡乱码入口 日本s色大片在线观看 | 亚洲精品成人久久久影院 | 天天操夜夜噜 | 狠狠色狠狠色狠狠五月ady | 一级黄免费 | 成 人 黄 色 视频 免费观看 | 在线成人aa在线看片 | 一级淫 | 99久久免费中文字幕精品 | 另类专区 亚洲 | 国产大片一区 | 手机看片福利视频 | 欧美国产亚洲一区 | 毛片大全在线 | 亚洲精品成人a在线观看 | 日韩在线第一区 | 美国黑人特大一级毛片 | 日韩一区二区天海翼 | 黄+色+性+人免费 | 国产露脸3p普通话 | 欧美一级成人一区二区三区 | 特级毛片免费视频播放 | 99在线看 | 亚洲久久在线观看 | 婷婷尹人香蕉久久天堂 | 国产精品手机在线观看 | 久久精品一区二区三区四区 | 久草最新网址 | 三级中文字幕永久在线视频 | 久久99国产乱子伦精品免费 | 成人18免费视频 | 欧美精品免费在线 | 日韩免费一级毛片 | 绝对真实偷拍盗摄高清在线视频 | 日本亚欧乱色视频在线网站 |