I
I
idin2018-01-19 16:53:21
Python
idin, 2018-01-19 16:53:21

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

In general, how can I predefine a method to connect to impap through a proxy, what is my mistake?
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

2 answer(s)
D
Dimonchik, 2018-01-21
@dimonchik2013

setup on local socks proxy
test through it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question