using imap_open behind proxy

Discussion in 'PHP' started by nashbur, Mar 5, 2009.

  1. #1
    Hi,

    I sit inside a lan whose outgoing traffic is routed through a proxy server. and it requires authentication. E.g. to open www.gmail.com using firefox, i have to select 'manual proxy configuration' option. i give server n port number there. n provide username n password (for proxy).

    Now here is my problem.
    $connection = imap_open('{imap.gmail.com:993/ssl}', 'xyz@gmail.com', 'gmail-password') or die("can't connect: " . imap_last_error());

    Usually this should connect to gmail inbox. but since I am behind a proxy, the proxy also needs to be authenticated. I am stuck about how to do that.

    To explain more, i will give one more example. While using 'wget' , I have to set
    http_proxy = http://proxy-server:80/
    proxy-user = proxy-user
    proxy-passwd = proxy-pass

    So, I think, for imap_open also, i will have to do similar thing. but im not sure how to do that.
    can anyone help?

    thanks
     
    nashbur, Mar 5, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Does your proxy even allow non-web connections?
     
    SmallPotatoes, Mar 5, 2009 IP
  3. nashbur

    nashbur Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes. I think so. I used the code for verification

    $szProxyAuth = base64_encode('USERNAME:pASS');
    header("Proxy-Authorization: Basic $szProxyAuth");
    header("Location: http://www.gmail.com");

    This opened the gmail page.
    But what i really want is,
    imap_open() should use these username:password and proceed further to make connection with imap.gmail .
    There are some suggestion like : use curl. But really, i dont want to download any page. I just want to make connection with gmails's imap and retrieve mails
     
    nashbur, Mar 6, 2009 IP
  4. nashbur

    nashbur Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    To help you more understand the problem, here is the error I am getting.

    Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl/tls}INBOX in /home/www/mysite/php/connection.php on line 7
    Array ([0] => Can't open mailbox {imap.gmail.com:993/imap/ssl/tls}INBOX: invalid remote specification )

    is this really because of proxy problem?

    guys, please help
     
    nashbur, Mar 7, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    In the code above (http://www.gmail.com) you are opening a web connection. That's different from an IMAP connection in two crucial ways:

    1) It's on a different port, which may be excluded by rule in the proxy or firewall setup.

    2) It uses a different protocol (IMAP vs HTTP). The proxy server may not understand IMAP and may not allow the CONNECT command to bypass application-level proxying.

    Until you confirm that your proxy is even willing to let you make an IMAP connection, I think you're wasting your time trying to look for less obvious issues.
     
    SmallPotatoes, Mar 7, 2009 IP