Answer the question
In order to leave comments, you need to log in
I'm trying to connect through a proxy to imap but it doesn't work. Where is the mistake?
I have a code that downloads mail from me and sorts it into all sorts of folders and I want to do it through a purchased proxy
, but for some reason I can’t connect. At this stage, it writes an error like this:
Socket error: 0x06: TTL expired
from imaplib import IMAP4, IMAP4_PORT, IMAP4_SSL_PORT,IMAP4_SSL
from socks import socksocket, PROXY_TYPE_SOCKS4, PROXY_TYPE_SOCKS5, PROXY_TYPE_HTTP
import ssl
class SOCKS_IMAP4_SSL(IMAP4_SSL):
def __init__(self, host, port = IMAP4_SSL_PORT, proxy = None,):
self.proxy = proxy
self.proxy_type = PROXY_TYPE_SOCKS5
IMAP4_SSL.__init__(self, host, port)
def open(self, host, port=IMAP4_SSL_PORT):
self.host = host
self.port = port
self.sock = socksocket()
#actual privoxy default setting, but as said, you may want to parameterize it
if self.proxy and self.proxy_type:
proxy_ip,proxy_port = self.proxy.split(':')
print('*')
self.sock.setproxy(self.proxy_type, proxy_ip,int(proxy_port))
print('**')
self.sock.connect((host,port))
print('777')
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
self.file = self.sslobj.makefile('rb')
def imap_check_all(login, password,proxy_type, proxy, imap_server='imap.mail.ru'):
mail = SOCKS_IMAP4_SSL(imap_server,proxy_type, proxy)
mail.login(login, password)
... дальше код проверяющий и сортирующий почту по папкам ....
accaunt_doc='мой аккаунт'
прокси='мой прокси'
imap_check_all(login, password,PROXY_TYPE_SOCKS5,proxy_ip)
P.S. Прокси точно работает я вроде как проверял его
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question