#!/usr/bin/python#coding:utf-8import smtplibfrom email.MIMEMultipart import MIMEMultipartfrom email.MIMEText import MIMETextmail_host = "smtp.163.com"mailto_list = "AAAAA@163.com"mail_user = "BBBBB@163.com"mail_pass = "password"message = """From: From PersonTo: To Person Subject: SMTP e-mail testThis is a test e-mail message."""def SendMail(sub,message): msg = MIMEMultipart() msg['From'] = mail_user msg['To'] = mailto_list msg['Subject'] = sub msg.attach(MIMEText(message, _charset="utf-8")) try: smtpObj = smtplib.SMTP_SSL(mail_host) smtpObj.login(mail_user, mail_pass) smtpObj.sendmail(mail_user,mailto_list, msg.as_string()) print "Successfully sent email" except Exception, e: print e print "Error: unable to send email"if __name__ == "__main__": SendMail("邮件标题", "邮件内容")