# 代码
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author:supery import smtplib from email.mime.text import MIMEText from email.utils import formataddr class BaseMessage(object): def send(self, subject, body, to, name): raise NotImplementedError(‘未实现send方法‘) class Email(BaseMessage): def __init__(self): self.email=‘[email protected]‘ self.user = ‘Supery‘ self.pwd = ‘xxx‘ def send(self, subject, body, to, name): msg = MIMEText(body,‘plain‘,‘utf-8‘) msg[‘Form‘] = formataddr([self.user,self.email]) msg[‘To‘] = formataddr([name,to]) msg[‘Subject‘] = subject server = smtplib.SMTP(‘smtp.163.com‘,25) server.login(self.email,self.pwd) server.sendmail(self.email,[to,],msg.as_string()) server.quit()
# 使用
Email(‘[email protected]‘,‘liu‘,‘你别走了‘,‘xxx太多了‘)