2016-07-27 75 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()