@@ -0,0 +1,1288 @@
+#-*- coding:utf-8 -*-%0A%0Aimport smtplib%0Afrom email.mime.text import MIMEText%0Afrom email.header import Header%0Afrom tools.config import Config%0Aclass MailSender(object):%0A%09def __init__(self,email_content,*,host=None,port=None,username=None,password=None,mail_server=smtplib.SMTP):%0A%09%09self._mail_content=email_content%0A%09%09self._host=host or Config.mail.host%0A%09%09self._port=port or Config.mail.port%0A%09%09self._username=username or Config.mail.user%0A%09%09self._password=password or Config.mail.password%0A%09%09self._mail_server=mail_server%0A%09def get_mail_subject(self):%0A%09%09return self._mail_content.get('subject')%0A%09def get_mail_sender(self):%0A%09%09return self._mail_content.get('sender')%0A%09def get_mail_receiver(self):%0A%09%09return self._mail_content.get('receiver')%0A%09def get_mail_main(self):%0A%09%09return self._mail_content.get('main')%0A%09def mail_encapsulate(self):%0A%09%09msg=MIMEText(self.get_mail_main(),'html','utf-8')%0A%09%09msg%5B'From'%5D=self.get_mail_sender()%0A%09%09msg%5B'To'%5D=self.get_mail_receiver()%0A%09%09msg%5B'subject'%5D=Header(self.get_mail_subject(),'utf-8').encode()%0A%09%09return msg%0A%09def send_mail(self):%0A%09%09server=self._mail_server(self._host,self._port)%0A%09%09server.starttls()%0A%09%09server.login(self._username,self._password)%0A%09%09server.sendmail(self.get_mail_sender(),self.get_mail_receiver(),self.mail_encapsulate().as_string())%0A%09%09server.quit()%0A%0A

add MailSender