0 votes
by (180 points)

Hello,

I want to connect to an exchange server via imap, but i get a "invalid imap response" error when using port 143 and "invalid tls packet received" error when using port 993 with implicit security.

Is it a configuration problem of the mailserver or is there an error in our code?

We are using Rebex R2016 R1.1

Following the rebex log:
First using port 143 with no Security and explicit sucurity

2016-06-21 15:10:52.120 Opening log file.
2016-06-21 15:10:52.121 Using FileLogWriter version 2.0.5885.0.
2016-06-21 15:10:52.129 DEBUG Imap(1)[1] Info: State changed from 'Disconnected' to 'Connecting'.
2016-06-21 15:10:52.130 INFO Imap(1)[1] Info: Connecting to <URL>:143 using Imap 2.0.5885.0.
2016-06-21 15:10:52.131 INFO Imap(1)[1] Info: Connecting to <URL>.
2016-06-21 15:10:52.151 DEBUG Imap(1)[1] Info: Connection succeeded.
2016-06-21 15:10:52.154 DEBUG Imap(1)[1] Info: State changed from 'Connecting' to 'Reading'.
2016-06-21 15:10:52.158 INFO Imap(1)[1] Response: 220 <URL> Microsoft ESMTP MAIL Service ready at Tue, 21 Jun 2016 15:10:51 +0200
2016-06-21 15:10:52.160 DEBUG Imap(1)[1] Info: State changed from 'Reading' to 'Disconnected'.
2016-06-21 15:10:52.163 ERROR Imap(1)[1] Info: Rebex.Net.ImapException: Invalid IMAP response.
   bei Rebex.Net.Imap.ME(String Z, CCX D, String J, Boolean C)
   bei Rebex.Net.Imap.RW(String Z, Int32 D, TlsParameters J, SslMode C)

Second using port 993 with implicit security

2016-06-21 15:11:23.941 Opening log file.
2016-06-21 15:11:23.941 Using FileLogWriter version 2.0.5885.0.
2016-06-21 15:11:23.949 DEBUG Imap(1)[1] Info: State changed from 'Disconnected' to 'Connecting'.
2016-06-21 15:11:23.950 INFO Imap(1)[1] Info: Connecting to <URL>:993 using Imap 2.0.5885.0.
2016-06-21 15:11:23.951 INFO Imap(1)[1] Info: Connecting to <URL>.
2016-06-21 15:11:23.968 DEBUG Imap(1)[1] Info: Connection succeeded.
2016-06-21 15:11:23.972 DEBUG Imap(1)[1] Info: Upgrading connection to TLS/SSL.
2016-06-21 15:11:23.994 INFO Imap(1)[1] TLS: State StateChange:Negotiating
2016-06-21 15:11:23.994 DEBUG Imap(1)[1] TLS: HandshakeMessage:ClientHello was sent.
2016-06-21 15:11:23.999 DEBUG Imap(1)[1] TLS: Invalid TLS packet received:
 0000 |32-32-30-20-45-4D-41-49 4C-2E-73-74-72-61-74-6D| 220 EMAIL.stratm
 0010 |61-6E-6E-2D-65-6E-74-73 6F-72-67-75-6E-67-2E-64| ann-entsorgung.d
 0020 |65-20-4D-69-63-72-6F-73 6F-66-74-20-45-53-4D-54| e Microsoft ESMT
 0030 |50-20-4D-41-49-4C-20-53 65-72-76-69-63-65-20-72| P MAIL Service r
 0040 |65-61-64-79-20-61-74-20 54-75-65-2C-20-32-31-20| eady at Tue, 21 
 0050 |4A-75-6E-20-32-30-31-36 20-31-35-3A-31-31-3A-32| Jun 2016 15:11:2
 0060 |33-20-2B-30-32-30-30-0D 0A                     | 3 +0200..
2016-06-21 15:11:24.006 DEBUG Imap(1)[1] TLS: Error while processing TLS packet: Rebex.Net.TlsException: Fatal error 'ProtocolVersion' has been encountered on the local connection end.
   bei Rebex.Net.WVX.JP()
   bei Rebex.Net.WVX.KP()

and the source code of connection in our interface:

if (nPort == 993)
    this.Imap.Connect(this.URL, Rebex.Net.SslMode.Implicit);
else 
{
   if (nSSL == 1)
       this.Imap.Connect(this.URL, nPort, Rebex.Net.SslMode.Explicit);
   else
       this.Imap.Connect(this.URL, nPort, Rebex.Net.SslMode.None);
}
this.Imap.Login(sUser, sPassword);
Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (70.2k points)

Hello,

the 220 <URL> Microsoft ESMTP MAIL Service ready message refers to an SMTP server not an IMAP server.

You can use Rebex.Net.Smtp class to connect to this server, however, it is really bad practice to run SMTP service on IMAP ports.

...