2016-07-27 274 views
3

我想用smtplib在python 2.7中发送邮件。下面的代码很简单:smtplib.SMTPAuthenticationError:(535,'5.7.3身份验证不成功')

import smtplib 

def main(argv=None): 

    sender = '[email protected]' 
    receivers = ['[email protected]']  

    message = """ 
    This is a test e-mail message. 
    """ 

    smtpObj = smtplib.SMTP('[email protected]',25) 

    smtpObj.login('abc', 'pwd')  
    smtpObj.sendmail(sender, receivers, message)   
    print "Successfully sent email" 


if __name__ == '__main__': 
main() 

现在,当我执行下面的代码,我不断收到此异常:

smtplib.SMTPAuthenticationError:(535, '5.7.3身份验证不成功')。

请注意。

谢谢,

回答

3

其实,当我试图执行Python控制台上相同的语句,我才知道密码是不正确的,这是由于不同的字符编码。

对于所有其他用户,从复制粘贴避免自己

two muppets

+0

同样的事情,我也忘了 –

1

有同样的问题。

2个选项,

尝试改变:

smtpObj = smtplib.SMTP('[email protected]',25) 

到:

smtpObj = smtplib.SMTP('[email protected]',587) 

其他选项是您的登录是不正确的。在我的情况即时通讯使用的交流和登录名并不电子邮件ADRES只是用户名

这里使用的Exchange Server的代码IM:

import smtplib 

def sendmail(): 
    subject = 'message subject' 
    to = '[email protected]' 
    sender = '[email protected]***.nl' 
    smtpserver = smtplib.SMTP("mail.mymailserver.nl",587) 
    user = 'myussername' 
    password = 'mypassword' 
    smtpserver.ehlo() 
    smtpserver.starttls() 
    smtpserver.ehlo 
    smtpserver.login(user, password) 
    header = 'To:' + to + '\n' + 'From: ' + sender + '\n' + 'Subject:' + subject + '\n' 
    message = header + '\n This is my message' 
    smtpserver.sendmail(sender, to, message) 
    smtpserver.close()