question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an HttpProxyClient for use with the various protocol clients

See original GitHub issue

Describe the bug I have successfully tested the mailkit imap class with 2 differents imap account (outlook and gmail) without using proxy I am not able to connect to our http proxy in any mode, i don’t have a socks proxy. The connection to the proxy is Ok but when i call the connect method i have the error posted below. This is the code i have used. What i am doing wrong?

To Reproduce

client = new ImapClient(new ProtocolLogger("imap.log"))
                {
                    ServerCertificateValidationCallback = (s, c, h, e) => true,
                    CheckCertificateRevocation = false
                };
string proxyServer = "192.168.16.19";
                int proxyPort = 8080;
                string proxyUsername = "admin";
                string proxyPassword = "password";
                string b64UserPwd = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(proxyUsername + ":" + proxyPassword));
                Socket mySocket = new Socket(SocketType.Stream, ProtocolType.Tcp);
                mySocket.Connect(proxyServer,proxyPort);
                string connectMsg = string.Format("CONNECT {0}:{1} HTTP/1.0\r\n" + "Proxy-Authorization: Basic {2}\r\n" + "\r\n", 
                    proxyServer, 
                    proxyPort,
                    b64UserPwd);
                byte[] msg = Encoding.UTF8.GetBytes(connectMsg);
                mySocket.Send(msg);
                string proxyConnectionResponseHeader = "";
                while (!proxyConnectionResponseHeader.Contains("\r\n\r\n"))
                {
                    byte[] buffer = new byte[1];
                    mySocket.Receive(buffer, 0, 1, 0);
                    proxyConnectionResponseHeader += Encoding.ASCII.GetString(buffer);
                }
                if (!proxyConnectionResponseHeader.Contains("200 Connection established"))
                {
                    throw new Exception("Connection to Proxy Failed: " + proxyConnectionResponseHeader);
                }

 var mode = _appModel.UseSSL ? SecureSocketOptions.SslOnConnect :                                                 SecureSocketOptions.None;
                    client.Connect(mySocket,
                        _appModel.Server,
                        _appModel.Port,
                        mode);

Screenshots image

Desktop (please complete the following information):

  • OS: Windows 10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
jstedfastcommented, Apr 19, 2019

Try the MyGet package once it’s published by the build bots (next 30 minutes or so?) and use MailKit.Net.Proxy.HttpProxyClient.

(Note: the main MailKit github page provides download links to official NuGet release packages as well as MyGet CI builds)

2reactions
biasccommented, Apr 19, 2019

@Safirion I have used this code https://github.com/poma/ProxySocket/blob/master/src/Org.Mentalis.Network.ProxySocket/ProxySocket.cs and it works. @jstedfast maybe it can be used to create a standard implementation in mailkit?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use the Proxy Protocol to Preserve a Client's IP Address
In this blog post, you'll learn how the Proxy Protocol preserves a client's IP address when that client's connection passes through a proxy....
Read more >
http-proxy-client-async v0.3.1
Async I/O HTTP 1.1 CONNECT proxy client protocol implementation.
Read more >
Proxy Protocol with Nginx Reverse Proxy
1 Answer 1 · Use the proxy_bind directive (cf. proxy_bind) to tell nginx to spoof its source address (to use the one from...
Read more >
HTTP Proxy Client Configuration - LogScale Documentation
LogScale will use the proxy for sending messages from actions and communicating with S3. To set up an HTTP proxy, use the following...
Read more >
12 HTTP Client and Web Debugging Proxy Tools
This tool provides an HTTP command for sending requests, all with the use of a natural syntax. HTTPie can be used for debugging,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found