The handshake failed due to an unexpected packet format

Most likely your server requires implicit SSL. So first try to connect without SSL:

// C#

client.Connect("imap.example.com");
' VB.NET

client.Connect("imap.example.com");

Then, before logging-in, start implicit SSL negotiation. The command name differs for different protocols:

In case of IMAP:

// C#

client.StartTLS();
' VB.NET

client.StartTLS()

In case of POP3:

// C#

client.STLS();
' VB.NET

client.STLS()

In case of SMTP:

// C#

client.StartTLS();
' VB.NET

client.StartTLS()

Now, your connection is secured.

Remember that you can ignore SSL certificate errors using ServerCertificateValidate event:

// C#

client.ServerCertificateValidate +=
    (sender, e) => { e.IsValid = true; };
' VB.NET

client.ServerCertificateValidate += Function(sender, e) Do
	e.IsValid = True
End Function

Tags: , , , , ,

Leave a Reply