holdtom
自带的smtplib本身就支持发送HTML邮件
def send_mail(self, recipients, subject, body):
msg = MIMEMultipart('alternative')
msg.set_charset("utf-8")
msg['Subject'] = subject
msg['From'] = self.__email_from
msg['To'] = ";".join(recipients)
body = MIMEText(body, 'html', "utf-8")
msg.attach(body)
try:
client = smtplib.SMTP(self.__smtp_server_host)
client.login(self.__smtp_user_name, self.__smtp_user_password)
client.sendmail(self.__email_from, recipients, msg.as_string())
return True
except Exception, e:
traceback.print_exc()
logging.error(e)
return False