亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

python 發送qq郵件的示例

瀏覽:75日期: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
相關文章:
主站蜘蛛池模板: a级网站在线观看 | 中文字幕免费在线观看动作大片 | 99re5精品视频在线观看 | 亚洲人成网站色7799在线观看 | 国产永久在线 | 国产成人精品视频午夜 | 天天射色综合 | 国产精品剧情原创麻豆国产 | 国产成人精选免费视频 | 亚洲色图首页 | 久久久久久久久国产 | 特黄一级片 | 欧美精品亚洲精品日韩一区 | 久久久久久免费精品视频 | 国产在线综合一区二区三区 | 乱爱性全过程免费视频 | 网红主播vip福利视频 | 韩国免费播放一级毛片 | 成人欧美在线观看 | 在线欧美精品一区二区三区 | 小泽玛利亚一区二区在线看 | 免费看的黄色大片 | 色片免费在线观看 | 99草视频| 伊人久久久久久久久香港 | 日本黄色高清网站 | 国产精品久久二区三区色裕 | 在线观看香蕉免费啪在线观看 | 女人一级毛片免费观看 | 亚欧毛片 | 国产一级一级一级成人毛片 | 日韩精品视频在线 | 国产喷水吹潮视频在线播放 | 无人精品乱码一区二区三区 | 一级欧美一级日韩片 | 多人性激烈的欧美三级视频 | 免费看a毛片 | 特一级大黄在线观看 | 日韩字幕无线乱码 | 特黄特色大片免费 | 黄色片在线免费观看视频 |