av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

python 發送qq郵件的示例

瀏覽:86日期:2022-06-24 17:26:22

python自帶了兩個模塊smtplib和email用于發送郵件。smtplib模塊主要負責發送郵件,它對smtp協議進行了簡單的封裝。email模塊主要負責郵件的構造。

email包下有三個模塊:MIMEText,MIMEImage,MIMEMultipart

發送純文本qq郵件

import smtplibfrom email.header import Headerfrom email.mime.text import MIMETextsender = ’888888@qq.com’ # 發送使用的郵箱receivers = [’888888@qq.com’] # 收件人,可以是多個任意郵箱message = MIMEText(’這里是正文!’, ’plain’, ’utf-8’)message[’From’] = Header('發送者', ’utf-8’) # 發送者message[’To’] = Header('接收者', ’utf-8’) # 接收者subject = ’這里是主題!’message[’Subject’] = Header(subject, ’utf-8’)try: # qq郵箱服務器主機 # 常見其他郵箱對應服務器: # qq:smtp.qq.com 登陸密碼:系統分配授權碼 # 163:stmp.163.com 登陸密碼:個人設置授權碼 # 126:smtp.126.com 登陸密碼:個人設置授權碼 # gmail:smtp.gmail.com 登陸密碼:郵箱登錄密碼 smtp = smtplib.SMTP_SSL(’smtp.qq.com’) # 登陸qq郵箱,密碼需要使用的是授權碼 smtp.login(sender, ’abcdefghijklmn’) smtp.sendmail(sender, receivers, message.as_string()) smtp.quit() print('郵件發送成功')except smtplib.SMTPException: print('Error: 無法發送郵件')

python 發送qq郵件的示例

發送HTML格式郵件

html = '''<html> <body> <h2> HTML </h2> <div style=’font-weight:bold’> 格式郵件 </div> </body> </html> ''' message = MIMEText(html,’html’, ’utf-8’)

python 發送qq郵件的示例

發送HTML格式郵件帶圖片

html = '''<html> <body> <h2> HTML </h2> <div style=’font-weight:bold’> 格式郵件帶圖片 </div> <img src='cid:imageTest'> </body> </html> '''message = MIMEMultipart(’related’)messageAlter = MIMEMultipart(’alternative’)message.attach(messageAlter)messageAlter.attach(MIMEText(html, ’html’, ’utf-8’))# 指定圖片為當前目錄fp = open(’test.png’, ’rb’)messageImage = MIMEImage(fp.read())fp.close()# 定義圖片ID,和圖片中的ID對應messageImage.add_header(’Content-ID’, ’<imageTest>’)message.attach(messageImage)

python 發送qq郵件的示例

發送帶附件郵件

from email.mime.multipart import MIMEMultipartmessage = MIMEMultipart()message.attach(MIMEText(’這里一封帶附件的郵件!’, ’plain’, ’utf-8’))# 添加附件# 其他格式如png,rar,doc,xls等文件同理。attach = MIMEText(open(’test.txt’, ’rb’).read(), ’base64’, ’utf-8’)attach['Content-Type'] = ’application/octet-stream’attach['Content-Disposition'] = ’attachment; filename='test.txt'’message.attach(attach)

python 發送qq郵件的示例

以上就是python 發送qq郵件的示例的詳細內容,更多關于python 發送qq郵件的資料請關注好吧啦網其它相關文章!

標簽: qq Python
相關文章:
主站蜘蛛池模板: 欧美国产激情二区三区 | 亚洲视频二区 | 在线视频一区二区三区 | 自拍偷拍视频网 | 久久免费福利 | 黄色片在线看 | 国产成人精品一区二区三区 | 亚洲国产成人av好男人在线观看 | 一级片av| 亚洲xxxxx| 日本黄色短片 | 国产精品久久久久久久久久久久冷 | 极品的亚洲 | 色精品| 久久精品久久久久久 | 久久91av | 欧美 日本 国产 | 日韩黄| 四虎成人精品永久免费av九九 | 黄网站在线播放 | 黄色成人免费看 | 91精品国产综合久久精品 | 黄色精品 | 五月天婷婷久久 | 97精品一区二区 | 中文字幕欧美在线观看 | 日韩视频在线播放 | 亚洲精品视频网站在线观看 | 亚洲国产高清免费 | 欧美成人精品一区二区男人看 | 久久久国产视频 | 亚洲一区在线日韩在线深爱 | 欧美 日韩 中文 | 欧美午夜精品久久久久免费视 | av一区二区三区 | 麻豆精品久久 | 国产高清在线精品一区二区三区 | 天堂中文在线播放 | 欧美日韩在线视频一区 | 精品国产欧美一区二区 | 亚洲精品一区二区三区蜜桃久 |