1. 程式人生 > >python 發送qq郵件

python 發送qq郵件

mime 失敗 smtplib -s quit lib .text 郵箱 fin

# coding=utf-8
import smtplib
from email.mime.text import MIMEText
import email

def sen(file_new):
msg_from = [email protected]# 發送方郵箱
passwd = ‘xthwzlXXX‘ # 填入發送方郵箱的授權碼
msg_to = [email protected]# 收件人郵箱

subject = "python郵件測試" # 主題

content = "這是我使用python smtplib及email模塊發送的郵件" # 正文
msg = MIMEText(content)
msg[‘Subject‘] = subject
msg[‘From‘] = msg_from
msg[‘To‘] = msg_to

try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465) # 郵件服務器及端口號
s.login(msg_from, passwd)
s.sendmail(msg_from, msg_to, msg.as_string())
print("發送成功")
except :
print("發送失敗")

finally:
s.quit()

python 發送qq郵件