import smtplib
from email.mime.text import MIMEText
mailto_list=["xxxx@163.com","xxx@163.com"]
mail_host="stmp.163.com"
mail_user="xxxx"
mail_pass="xxxx"
mail_postfix="163.com"
def send_mail(to_list,sub,content):
me="XXX"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,_subtype='html',_charset='gb2312')
msg['Subject'] = sub
msg['From'] = me
msg['To'] = ";".join(to_list)
try:
s = smtplib.SMTP()
s.connect(mail_host)
s.login(mail_user,mail_pass)
s.sendmail(me, to_list, msg.as_string())
s.close()
return True
except Exception, e:
print str(e)
return False
if __name__ == '__main__':
if send_mail(mailto_list,"这里是邮件标题!",
"<pre>Hi All:<br/>\
今天的天气不错哦<br/>\
所以要不要出去玩? <br/>快来跟我说下吗!<br/><br/>\
</pre>"):
print "发送成功"
else:
print "发送失败"