smtplib.SMTP无法登录

bjo*_*eph 1 python email python-2.7 anaconda

我想从python脚本发送一封电子邮件.但是,当我尝试运行时,server.login我收到以下错误:smtplib.SMTPAuthenticationError: (535, '5.7.0 (#MBR1212) Incorrect username or password.')

我已尝试使用Gmail和Yahoo帐户.Gmail错误是:

smtplib.SMTPAuthenticationError: (535, '5.7.8 Username and Password not accepted. Learn more at\n5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 u2sm21203448pbs.42 \
- gsmtp')
Run Code Online (Sandbox Code Playgroud)

雅虎的错误是

smtplib.SMTPAuthenticationError: (535, '5.7.0 (#MBR1212) Incorrect username or password.')
Run Code Online (Sandbox Code Playgroud)

我正在使用的代码如下.用户名和密码是表示我的正确用户名和密码的字符串变量.

server = smtplib.SMTP('smtp.mail.yahoo.com', 587)
server.ehlo()
server.starttls()
server.login(username, password)
Run Code Online (Sandbox Code Playgroud)

我在用 Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, May 27 2014, 14:58:54)

Sae*_*ghi 5

你应该去雅虎电子邮件帐户,然后去Account security积极Allow apps that use less secure sign in解决你的问题.