0 votes


I need to send e-mails passing by a proxy.

Just to clarify, I'll organize the task into two steps: i) Step 1 consists in generating the token, through the Microsoft Identify Libraries. I have no problem with this step.

ii) The second step, consists in sending or receiving e-mail, using the account and/or the token generated by step 1. Here is the problem. I have been not found a place to inform the proxy of the connection.

The code is listed below:

Using client As New Imap()


    ' Here we receive error **


End Using

Could anyone help me ?

Thank you

by (400 points)

1 Answer

0 votes

If you want to use a proxy server you need to reference and use Proxy.dll,
that can be found in the download package:

Here's the code that shows how to use a proxy client and SSL/TLS encryption:

' VB.NET version

Dim factory As New ProxyFactory()
Dim proxy As IProxyClient = factory.CreateProxy( _
   ProxyType.Http, "", 80)

Dim socket As Socket = proxy.Connect( _
    "imap.gmail.com",  _

Using imap As New Imap()
   imap.AttachSSL(socket, "imap.example.com")

   ' regular imap code

End Using
by (295k points)

Thank you for replying me.

I implemented the code, but I'm still receiving errors. Could you help me ? What isis my mistake?

The Code

Dim factory As New ProxyFactory()
Dim proxy As IProxyClient = factory.CreateProxy(ProxyType.Http, classRegrasDoNegocio.venderecoproxy, Integer.Parse(classRegrasDoNegocio.vportaproxy),
classRegrasDoNegocio.vusuarioproxy, classRegrasDoNegocio.vsenhaproxy)

The error occurs here in this line \/
Dim socket As Socket = proxy.Connect("smtp.office365.com", Smtp.DefaultSSLPort)
client.AttachSSL(socket, "smtp.office365.com")


The error:

Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I already tested removing the Proxy and in this case, there is no error.


Are you absolutely sure you are required to use a proxy?
99.9% of users do not require using a proxy server for connections.
What kind of proxy do you use? SOCKS proxy or HTTP proxy?

If there is no error without a proxy server it most likely mean that you have problems connecting to the proxy server.

Does your proxy server require authentication?