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

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

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

瀏覽:98日期: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 編程
相關文章:
主站蜘蛛池模板: 欧美一级久久久久久久久大 | 亚洲精品福利一区二区三区 | 中国黄色网址大全 | 国产欧美另类久久久精品免费 | 久久免费视频7 | 日本免费一区二区三区毛片 | 中文字幕亚洲精品第一区 | 国产成人精品免费视频网页大全 | 欧美成人精品久久精品 | 国产精自产拍久久久久久 | 久久免费国产精品一区二区 | 欧美一区二区三区男人的天堂 | 精品国产成人在线 | 精品a在线观看 | 亚洲视频在线观看免费视频 | 欧美 日韩 国产在线 | 欧美国产日韩在线 | 久久久成人影院 | 亚洲精品一区二区三区四区手机版 | 三级高清| 国产精品久久久久免费 | 国产日韩精品一区二区在线观看 | 美女一级毛片免费看看 | 99色在线视频| 男人天堂国产 | 欧美日韩在线第一页 | 亚洲男人的性天堂 | 久久www免费人成精品 | 日韩在线1 | 国产精品二 | 熟女毛片 | 国产成人午夜福在线观看 | 亚洲综合第一欧美日韩中文 | 性欧美欧美之巨大69 | 日韩一区二区三区四区 | 毛片免费永久不卡视频观看 | 免费永久在线观看黄网 | 草草影院免费 | 国产成人av性色在线影院 | 欧美一区二区在线视频 | 成 人 黄 色 视频播放16 |