#!/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()