我正在尝试发送电子邮件,而下面打开代理是一段代码。如果我单独运行每个部分,他们会工作(发送和发送电子邮件)。
import socks
import socket
import smtplib
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS4, '127.0.0.1', 9050, True)
socket.socket = socks.socksocket
FROM = "test@test"
TO = ["test1@test1"]
SUBJECT = "SB"
TEXT = "test"
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
server = smtplib.SMTP('localhost')
server.sendmail(FROM, TO, message)
server.quit()
当我加入他们时,我收到以下错误:
Traceback (most recent call last):
File "em.py", line 20, in <module>
server = smtplib.SMTP('localhost')
File "/usr/lib/python2.7/smtplib.py", line 249, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 309, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 284, in _get_socket
return socket.create_connection((port, host), timeout)
File "/usr/lib/python2.7/socket.py", line 562, in create_connection
sock.connect(sa)
File "/usr/local/lib/python2.7/dist-packages/socks.py", line 459, in connect
dest_addr, dest_port = dest_pair
ValueError: too many values to unpack
任何帮助都会得到帮助
答案 0 :(得分:0)
您正在连接到localhost;但是,如果您正在通过TOR代理,那么您基本上要求tor-exit连接到运行在他本地主机上的smtp服务器&#39;。这不起作用:
您希望如何运作?