wangdachui95345
2015-06-09 14:10
采纳率: 84.6%
浏览 9.9k
已采纳

python 发邮件 535, 'Error: authentication failed'

  import smtplib  
from email.mime.text import MIMEText  

mailto_list=["xxx@163.com"] 
mail_host="smtp.163.com"  
mail_user="xxxx@163.com"    
mail_pass="xxx"   


def send_mail(to_list,sub,content):  
                me="hello"
                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,"hello","<a href='http://www.cnblogs.com/'>hello</a>"):  
        print "success"  
    else:  
        print "fail"  
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

7条回答 默认 最新

相关推荐 更多相似问题