python通過smtp傳送qq郵件
import smtplib from email.mime.text import MIMEText from email.header import Header """ 1》測試郵件傳送 2》有收件人、發件人、主題、郵件內容 """ sender = `xx@qq.com` receivers = [`xx@qq.com`, `xx@qq.com`] # 接收郵件,可設定為你的QQ郵箱或者其他郵箱 # 三個引數:第一個為文字內容,第二個 plain 設定文字格式,第三個 utf-8 設定編碼 message = MIMEText(`您好! 我的賬號不能寫部落格,麻煩解封一下,謝謝`, `plain`, `utf-8`) message[`From`] = sender message[`To`] = `;`.join(receivers) subject = `賬號解封` message[`Subject`] = Header(subject, `utf-8`) smtpObj = smtplib.SMTP(`smtp.qq.com`, 25) smtpObj.starttls() smtpObj.login(sender, `stmp授權密碼`) smtpObj.sendmail(sender, receivers, message.as_string()) print(`success`)
遇到的問題:
- smtplib.SMTPAuthenticationError: (535, b`Error..)
授權失敗,剛開始smtpObj.login(sender, `stmp授權密碼`),傳入的密碼是qq密碼,需要qq郵箱設定中開啟smtp服務,獲得授權碼