我无法从python发送电子邮件。可能存在安全问题。有人可以给我一个暗示吗? 这是代码:
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
#Next, log in to the server
server.login("***@gmail.com", "PASSWORD")
#Send the mail
msg = "Hello!"
# The /n separates the message from the headers
server.sendmail("***@gmail.com", "***@gmail.com", msg)
server.quit()
这是我得到的错误:
server = smtplib.SMTP('smtp.gmail.com', 587)
File "D:\Tools\Lib\smtplib.py", line 244, in __init__
(code, msg) = self.connect(host, port)
File "D:\Tools\Lib\smtplib.py", line 310, in connect
raise socket.error, msg
error: (10060, 'Operation timed out')
答案 0 :(得分:0)
你应该使用smtplib.SMTP_SSL()因为端口587需要ssl(tls)来自get。
https://docs.python.org/2/library/smtplib.html#smtplib.SMTP_SSL
答案 1 :(得分:0)