Failed to connect IdPop3 to IdPop3Server over SSL
I have TIdPop3Server
in one application that is attached IdServerIOHandlerSSLOpenSSL1
and receives emails and sends them to the client TIdPop3
in another application (with one attached to it TIdSSLIOHandlerSocketOpenSSL
). Everything is fine when connections become insecure using port 110. But when I try to use the connection SSL
on port 995, I get an error Connection Closed Gracefully
after the attemp connection with the client fails. This is my event Pop3SeverOnConnect
:
procedure TMainForm.Pop3ServerConnect(AContext: TIdContext);
begin
if (AContext.Connection.IOHandler is TIdSSLIOHandlerSocketBase) then
TIdSSLIOHandlerSocketBase(AContext.Connection.IOHandler).PassThrough :=
(AContext.Binding.Port <> 995);
showmessage('SSL connection made!');
end;
And this is the client side:
procedure TMainForm.btnCheckMailBoxClick(Sender: TObject);
begin
IdSSLIOHandlerSocketOpenSSL1.PassThrough := False;
POP3Client.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
with POP3Client do begin
AuthType := patUserPass;
Host := myHost;
UserName := myUserName;
Password := myPass;
Port := myPort;
end;
try
POP3Client.Connect;
Except on e : Exception do
showmessage('error=' + e.Message);
end;
// code for retrieving message data
end;
And I always get an exception from Pop3Client.Connect
, as I mentioned above (the message SSL connection made!
never appears in the server application). If I use, however, another email client, for example, Mozilla Thunderbird
I get a successful SSL connection for port 995. So the problem must be somewhere in the client procedure, but who knows - that's why I'm asking you guys for help.
source to share
In your client code, you need to set a property TIdPOP3.UseTLS
instead of a property TIdSSLIOHandlerSocketOpenSSL.PassThrough
, for example:
procedure TMainForm.btnCheckMailBoxClick(Sender: TObject);
begin
with POP3Client do
begin
IOHandler := IdSSLIOHandlerSocketOpenSSL1;
AuthType := patUserPass;
UseTLS := utUseImplicitTLS; // <-- here
Host := myHost;
UserName := myUserName;
Password := myPass;
Port := myPort;
end;
try
POP3Client.Connect;
try
// code for retrieving message data
finally
POP3Client.Disconnect;
end;
except
on e : Exception do
ShowMessage('error=' + e.Message);
end;
end;
In your server code, you need to get rid of ShowMessage()
. TIdPOP3Server
is multi-threaded, the event is OnConnect
fired in the context of a worker thread, and ShowMessage()
not thread safe. If you must display a popup message, use Windows.MessageBox()
instead.
source to share