Python 无法发送电子邮件,并给出很长的错误消息
Python sending email won't work, and is giving long error messages
我正在测试 python 脚本来向自己发送电子邮件:
import smtplib
fromaddr = '----------@gmail.com'
toaddrs = '----------@gmail.com'
msg = 'GRRRRR!!!!!!'
username = '----------@gmail.com'
password = '----------'
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
其中“----------”的意思是"private information."这是我收到的错误消息:
Traceback (most recent call last):
File "ms.py", line 10, in <module>
server.login(username, password)
File "/usr/lib/python2.7/smtplib.py", line 615, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvXa\n5.7.14 z7t5LRUd-e-nGxiMetNBY2KaLd8EP3SJVhw2EwccDQjlUi0FxHegAH2YrpvKdYIX2lHz9N\n5.7.14 cMZ_w8kPxuXXhBPMbXA26tWu_HM0tt_4IC8aEct5VRz7z1J22epkLWXUx-COwh4rt2K2-_\n5.7.14 1Lw71Ag70CBpsqYpfzScV-_mF7zHl_NFRflAn5sFnPftR_bX6hhGAHxj5rz1bx0U44sByk\n5.7.14 t-arL3mQhKu-nfFzkcIvjlzuUh3w> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 p18sm2343352qkh.10 - gsmtp')
我做错了什么?
您可能需要:
server = smtplib.SMTP_SSL('smtp.gmail.com:465')
而不是:
server = smtplib.SMTP('smtp.gmail.com:587')
并且可能不需要 .ehlo ()
我正在测试 python 脚本来向自己发送电子邮件:
import smtplib
fromaddr = '----------@gmail.com'
toaddrs = '----------@gmail.com'
msg = 'GRRRRR!!!!!!'
username = '----------@gmail.com'
password = '----------'
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
其中“----------”的意思是"private information."这是我收到的错误消息:
Traceback (most recent call last):
File "ms.py", line 10, in <module>
server.login(username, password)
File "/usr/lib/python2.7/smtplib.py", line 615, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbvXa\n5.7.14 z7t5LRUd-e-nGxiMetNBY2KaLd8EP3SJVhw2EwccDQjlUi0FxHegAH2YrpvKdYIX2lHz9N\n5.7.14 cMZ_w8kPxuXXhBPMbXA26tWu_HM0tt_4IC8aEct5VRz7z1J22epkLWXUx-COwh4rt2K2-_\n5.7.14 1Lw71Ag70CBpsqYpfzScV-_mF7zHl_NFRflAn5sFnPftR_bX6hhGAHxj5rz1bx0U44sByk\n5.7.14 t-arL3mQhKu-nfFzkcIvjlzuUh3w> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 p18sm2343352qkh.10 - gsmtp')
我做错了什么?
您可能需要:
server = smtplib.SMTP_SSL('smtp.gmail.com:465')
而不是:
server = smtplib.SMTP('smtp.gmail.com:587')
并且可能不需要 .ehlo ()