【问题标题】:SMTP acting weirdlySMTP 行为怪异
【发布时间】:2019-02-05 07:59:55
【问题描述】:

我正在尝试在 python 中使用 SMTPLIB 发送消息,但是我收到一条错误消息。我很肯定使用的电子邮件和密码是正确的。我尝试通过网络浏览器登录和不登录来发送这个。正如以下 stackoverflow 文章所述:Error sending email: raise SMTPAuthenticationError(code, resp)。我在下面的代码中替换了单词而不是实际的电子邮件和密码:

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("senderemail", "senderemailpassword")

msg = "Hello!"
server.sendmail("senderemail", "recieveremail", msg)
server.quit()

错误信息:

Traceback (most recent call last):
  File "D:\Hussain\Hussain's computing\Python\emailingtest.py", line 5, in <module>
    server.login("senderemail", "senderpassword")
  File "C:\Users\Hammad\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 730, in login
    raise last_exception
  File "C:\Users\Hammad\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 721, in login
    initial_response_ok=initial_response_ok)
  File "C:\Users\Hammad\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 642, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b'5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbvT\n5.7.14 ULHSk5VkFjTMqIX_jl5P4GMOarejb0s0WpOqP5RRrWPijD_2GRXQ--JBo5t2r_5pz-ysoY\n5.7.14 Eqv-0GUXB4v321WRxe2uRR1FlFqSTWy-qwXSDmXkkWqwah1akDIy4iw73_mach6-KntI0A\n5.7.14 HLVsfpyrYaTDdeJd54pUPlCEI5W9kZiv48-Ir2-NhbL_rqHrg3OrC-432Uc90Rskt9qNd0\n5.7.14 vAm9r3GQr8jUxrYIgj9YUP0h8xr8HKFFDQSX_RcuTn2lSrXIuy> Please log in via\n5.7.14 your web browser and then try again.\n5.7.14  Learn more at\n5.7.14  https://support.google.com/mail/answer/78754 h7-v6sm8163217wrs.3 - gsmtp')

如果有人可以修复我的代码,那将非常有帮助。

【问题讨论】:

    标签: python python-3.x smtp smtplib python-3.7


    【解决方案1】:

    正如this tutorial 中提到的,它可能值得Displaying the unlock captcha

    【讨论】:

      【解决方案2】:

      默认情况下,Google 会阻止来自不使用现代安全标准的脚本/应用程序的任何登录尝试。但是,您可以更改该设置:https://www.google.com/settings/security/lesssecureapps

      【讨论】:

      • 谢谢,但我已经尝试过问题中提到的
      • 谷歌也有可能显示验证码。你确定你把提到的设置打开而不是关闭吗?
      • 不,我没有,我该如何阻止它?
      • accounts.google.com/DisplayUnlockCaptcha - 在这里您可以更改您的设置,更改后您应该等待几分钟再重新运行脚本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-15
      • 2019-11-03
      • 2012-08-05
      • 2012-12-03
      相关资源
      最近更新 更多