2016-12-12 114 views
0

我也跟着下面的步驟與蟒蛇script--認證的問題

import smtplib 
smtpUser='[email protected]' 
smtpPass='1234' 
toAdd='[email protected]' 
fromAdd=smtpUser 
subject='Python test' 
header='To:' +toAdd+'\n'+'From:'+fromAdd+'\n' +'Subject:'+ subject 
body='From within a python script' 

print(header + '\n'+ body) 
s= smtplib.SMTP('smtp.gmail.com',587) 
s.ehlo() 
s.starttls() 
s.ehlo() 
s.login(smtpUser,smtpPass) 
s.sendmail(fromAdd,toAdd,header +'\n' + body) 
s.quit() 

那麼錯誤味精發送電子郵件is--

Traceback (most recent call last): 
File "C:/Users/129/PycharmProjects/smtp.py", line 34, in <module> 
s.login(smtpUser,smtpPass) 
File "C:\WinPython-64bit-3.4.4.2\python-3.4.4.amd64\lib\smtplib.py", line 652, in login 
raise SMTPAuthenticationError(code, resp) 
smtplib.SMTPAuthenticationError: (501, b'5.5.2 Cannot Decode response q9sm74360527pfg.47 - gsmtp') 
Process finished with exit code 1 

可有人請解釋我是什麼是錯誤,如果我沒有錯,它是與谷歌安全有關。

回答

0

我用這從一個Gmail帳戶發送電子郵件:

s = smtplib.SMTP('smtp.gmail.com:587') 
s.starttls() 
s.login(username, password) 
s.sendmail(from_mail, to_mail, msg.as_string()) 
s.quit() 

看一看here。它爲我工作。