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

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

msg = MIMEMultipart()
msg["From"] = "fuhanw@qq.com"
msg["To"] = "fuhanw@foxmail.com"
msg["Subject"] = "这是一封来自Python的邮件"

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

smtp = smtplib.SMTP()
smtp.connect("smtp.qq.com", "25")
smtp.login("fuhanw@qq.com", "xxxxxxxx")
smtp.sendmail("fuhanw@qq.com", "fuhanw@foxmail.com", msg.as_string())
smtp.quit()
posted @ 2013-11-02 18:12  付翰文  阅读(558)  评论(0编辑  收藏  举报