好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > python 發送qq郵件的示例

python 發送qq郵件的示例

熱門標簽:廈門crm外呼系統如何 ai地圖標注 長春人工智能電銷機器人官網 百應ai電銷機器人鄭州 如何在地圖標注文字 地圖標注推廣單頁 n400電話申請多少錢 女王谷地圖標注 西藏快速地圖標注地點

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

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

發送純文本qq郵件

import smtplib
from email.header import Header
from email.mime.text import MIMEText

sender = '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: 無法發送郵件")

發送HTML格式郵件

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

發送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)

發送帶附件郵件

from email.mime.multipart import MIMEMultipart

message = 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 調用API發送郵件
  • Python基于SMTP發送郵件的方法
  • python基于SMTP發送QQ郵件
  • python 自動監控最新郵件并讀取的操作
  • python實現發送郵件
  • python 實現網易郵箱郵件閱讀和刪除的輔助小腳本
  • python如何發送帶有附件、正文為HTML的郵件
  • python使用Windows的wmic命令監控文件運行狀況,如有異常發送郵件報警
  • python 檢測nginx服務郵件報警的腳本
  • python實現發送QQ郵件(可加附件)
  • python實現定時發送郵件到指定郵箱
  • python實現定時發送郵件
  • Python基礎詳解之郵件處理

標簽:廊坊 黔東 渭南 亳州 內江 拉薩 綿陽 興安盟

巨人網絡通訊聲明:本文標題《python 發送qq郵件的示例》,本文關鍵詞  python,發送,郵件,的,示例,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《python 發送qq郵件的示例》相關的同類信息!
  • 本頁收集關于python 發送qq郵件的示例的相關信息資訊供網民參考!
  • 推薦文章