# coding=gb2312
import smtplib
from email.mime.text import MIMEText
#要发给谁
mailto_list= ["418778645@qq.com", "418778645@qq.com"]
def send_mail(to_list,sub,content):
#设置服务器,用户名、口令以及邮箱的后缀
mail_host="smtp.qq.com"
mail_user="418778645"
mail_pass="***********"
mail_postfix="qq.com"
me=mail_user+"<"+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__':
txt='<html> \
<body> \
<p> \
http://hi.baidu.com/zengzhaonong \
</p> \
<p> \
http://hi.baidu.com/zengzhaonong \
</p> \
</body> \
</html>'
if send_mail(mailto_list, "博客地址", txt):
print "发送成功"
else:
print "发送失败"
import smtplib
from email.mime.text import MIMEText
#要发给谁
mailto_list= ["418778645@qq.com", "418778645@qq.com"]
def send_mail(to_list,sub,content):
#设置服务器,用户名、口令以及邮箱的后缀
mail_host="smtp.qq.com"
mail_user="418778645"
mail_pass="***********"
mail_postfix="qq.com"
me=mail_user+"<"+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__':
txt='<html> \
<body> \
<p> \
http://hi.baidu.com/zengzhaonong \
</p> \
<p> \
http://hi.baidu.com/zengzhaonong \
</p> \
</body> \
</html>'
if send_mail(mailto_list, "博客地址", txt):
print "发送成功"
else:
print "发送失败"