mailer.py 811 Bytes
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import smtplib
from email.mime.text import MIMEText
from email.header import Header


class mailman(object):
    def __init__(self):
        self.sender = 'robot@yohoops.cn'
        self.smtpObj = smtplib.SMTP('localhost')
     
    def mail(self,receivers=[],Content='Test Mail',From ='Robot',To='YOHOOPS',Title='Test Mail'):
        message = MIMEText(Content, 'plain', 'utf-8')
        message['From'] = Header(From, 'utf-8') 
        message['To'] =  Header(To, 'utf-8') 
        message['Subject'] = Header(Title, 'utf-8')
     
        try:
            self.smtpObj.sendmail(self.sender, receivers, message.as_string())
            print "邮件发送成功"
        except smtplib.SMTPException:
            print "Error: 无法发送邮件"

        return 0