用Python的smtp模块发邮件的示例

# -*- coding: UTF-8 -*-
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

msg = MIMEMultipart()
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg["Subject"] = "这是一封来自Python的邮件"

text = MIMEText("这是一封来自Python的邮件 这是一封来自Python的邮件 这是一封来自Python的邮件")
msg.attach(text)

smtp = smtplib.SMTP()
smtp.connect("smtp.qq.com", "25")
smtp.login("[email protected]", "xxxxxxxx")
smtp.sendmail("[email protected]", "[email protected]", msg.as_string())
smtp.quit()

你可能感兴趣的:(用Python的smtp模块发邮件的示例)