我正试图通过 Gmail 用 Python 发送一封电子邮件,以下是我的代码:
import smtplib
fromaddr = '......................'
toaddrs = '......................'
msg = 'Spam email Test'
username = '.......'
password = '.......'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
我得到了一个错误:
Traceback (most recent call last):
File "email_send.py", line 18, in <module>
server.login(username, password)
File "C:\.....\Python\lib\smtplib.py", line 633
, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepte
d. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=1425
7\n5.7.8 {BADCREDENTIALS} s10sm9426107qam.7 - gsmtp')
这似乎是登录的一个问题。我确信我的登录信息是正确的,除了一件事。用户名应该是“ & quot; brah@gmail.com”,还是简单的“ brah”?我都试过了,一样的错误。
知道是怎么回事吗?
注意: 所有的句点代替了密码/电子邮件/文件路径等。