我的问题是,当我运行以下代码时,我得到一个 WinError 10061,从我的所有搜索来看,这似乎是由于没有正确设置外国机器,但我认为谷歌已经处理好了对于gmail,所以错误就在我这边。我能找到的所有其他示例都是使用 localhost 并出现此错误,这是因为他们没有设置本地邮件服务器。这个问题还会出现这种情况吗?我确定我遗漏了一些明显的东西。此外,错误代码是完整的。先感谢您!
import smtplib
fromaddr = 'email@email.com'
toaddrs = 'otheremail@email.com'
msg = 'Random stuff!'
username = 'username'
password = 'pass'
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
错误:
Traceback (most recent call last):
File "C:/Users/Brett/PycharmProjects/Texting/sendMessage.py", line 13, in <module>
server = smtplib.SMTP('smtp.gmail.com')
File "C:\Python33\lib\smtplib.py", line 238, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python33\lib\smtplib.py", line 317, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python33\lib\smtplib.py", line 288, in _get_socket
self.source_address)
File "C:\Python33\lib\socket.py", line 424, in create_connection
raise err
File "C:\Python33\lib\socket.py", line 415, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it