#来源忘了,就不贴链接地址了
#简单的python smtp发邮件代码
import smtplib
from email.mime.text import MIMEText
mailto_list=["123456789@qq.com","987654321@qq.com"]
mail_host="smtp.qq.com"
mail_user="123456789@qq.com"
mail_pass="***************"
mail_postfix="qq.com"
def send_mail(to_list,sub,content):
'''
to_list:发给谁
sub:主题
content:内容
send_mail("aaa@126.com","sub","content")
'''
me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
msg=MIMEText(content)
msg['Subject']=sub
msg['From']=me
msg['To']=";".join(to_list)
try:
s=smtplib.SMTP(port=465)
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__':
sub="hello baby(python test mail)"
content="乔装打扮,不择手段"
if send_mail(mailto_list,sub,content):
print "发送成功"
else:
print "发送失败"