paveltr
paveltr

Reputation: 474

Accessing gmail through imaplib with proxy authentification

I am getting crazy. I tried one of solutions to get through proxy:

class SocksIMAP4(IMAP4_SSL):
    def open(self, host, port):

            self.host = host
            self.port = port
            self.sock = socksocket()
            self.sock.set_proxy(PROXY_TYPE_SOCKS5, 'tmg-array.co.vectis.local', 8080, True, 'login',
                                'pass~')
            self.sock.connect((host, port))
            self.file = self.sock.makefile('rb')

And then

imap_server = SocksIMAP4('imap.gmail.com', 993)

But nothing happens. Process seems to be eternal.

It doesn't throw mistakes and program is like get frozen at the connection stage.

Any suggestions?

edited

my import is

import email
from imaplib import IMAP4_SSL, IMAP4_SSL_PORT, IMAP4, IMAP4_PORT
import re
import socks
import socket
from socks import socksocket, PROXY_TYPE_SOCKS4, PROXY_TYPE_SOCKS5, PROXY_TYPE_HTTP
import smtplib

Upvotes: 1

Views: 1714

Answers (1)

GAVD
GAVD

Reputation: 2134

I know it is late but I just want to post an answer for whom don't know.

Replacing three last lines of function open by these lines

self.sock = socket.create_connection((host, port), PROXY_TYPE_HTTP, "127.0.0.1", 8118)
self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
self.file = self.sslobj.makefile('rb')

Upvotes: 1

Related Questions