- 论坛徽章:
- 0
|
发送邮件的代码如下:
def send_email(host,src,des,subject,data,account,password):
""" send the email to user """
try:
Msg ['Subject'] = subject
Msg ['From'] = src
Msg ['To'] = des
Msg = MIMEText(data,_subtype='plain',_charset='gb2312')
print Msg
smtp = smtplib.SMTP(host)
smtp.login(account,password)
smtp.sendmail(src,des,Msg.as_string())
smtp.close()
except Exception,e:
raise Exception, str(e)
每次执行到smtp.login那里就出错了,返回的错误是error: (535, 'Error: authentication failed')
我用的是smtp.163.com做测试的, 用户名和密码是绝对正确的.
不知道这是为什么,哪位兄弟知道原因,麻烦告知一下,谢谢.
测试代码如下:
host = 'smtp.163.com'
src = "xxx@163.com"
des = 'xxx@163.com
subject = "hi "
data = "this is test!!"
username = "xxx@163.com"
password = "yourkey"
try:
send_email(host,src,des,subject,data,username,password)
print 'success!!'
except Exception,e:
print "error: %s" % str(e) |
|