【发布时间】: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