Long time ago I wrote following code to retrieve emails from mailbox:
pop3 := TNMPOP3.Create(Self);
try
pop3.Host := FAppSettings.ServerName;
pop3.Port := FAppSettings.ServerPort;
pop3.UserID := FAppSettings.Login;
pop3.Password := FAppSettings.Password;
try
pop3.Connect;
except
on E:Exception do AddError(E.Message);
end;
if not pop3.Connected then Exit;
if pop3.MailCount > 0 then begin
pop3.DeleteOnRead := False;
pop3.AttachFilePath := GetTempDirectory;
ProcessMsgs(pop3);
end
else begin
TCommon.InfMsg('There are no messages in mailbox');
end;
pop3.Disconnect;
finally
pop3.Free;
end;
Now, when mail service provider switched entirely to SSL this code fails obviously, but in a strange way:
pop3.Connect
line causes an exception but with an empty text in E.Message making the problem unclear to end user.
Investigation of the problem in Delphi debugger reveals that the first time the right exception is generated:
Project .... raised exception class Exception with message 'Authentication failed'.
but then, when I press F8 (Step Over) again, execution point remains in the same line and another exception is generated:
Project .... raised exception class Exception with message ''.
and only this exception is catched by try-except
.
Why?
To answer your actual question of "why?", the sequence you describe means that TNMPOP3.Connect()
is internally catching the original authentication exception and throwing a new exception without an error message. Whether that is a bug or intentional, there is no way to know without looking at the source code for TNMPOP3
. Delphi did not ship with that source code, and NetMasters are no longer around so you can't ask them for it. TNMPOP3
does not support SSL anyway, so you will have to switch to another component/library to handle your POP3+SSL functionality moving forward.