利用python实现简单邮件功能

#!/usr/bin/env python
# -*- coding:utf-8 -*-
import smtplib
from email.utils import formataddr
from email.mime.text import MIMEText
def email(p,text,subject):
    msg = MIMEText(text,'plain','utf-8')
    msg['From'] = formataddr(['xxx','xxxx@126.com'])
    msg['To'] = formataddr(['ooo','ssss@qq.com'])
    msg['Subject'] = subject

    sever = smtplib.SMTP('smtp.126.com',25)
    sever.login('xxxx@126.com','password')
    sever.sendmail('xxxx@126.com',[p,],msg.as_string())
    sever.quit()

 

posted @ 2017-02-09 07:23  Erick-LONG  阅读(224)  评论(0编辑  收藏  举报