Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Send a Raw POP3 Command
See more POP3 Examples
Demonstrates the Chilkat MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3 server and returns the server's response. The second argument specifies the charset to use if the command contains non-US-ASCII characters. This example sends the POP3 STAT command within an open session.
Background: POP3 is a simple line-based text protocol — the client sends short commands like
STAT, LIST, UIDL, or RETR and the server replies with +OK or -ERR. This method is an escape hatch for issuing a command Chilkat doesn't wrap directly, or a server-specific extension. Note that the session must already be open, since a raw command assumes an authenticated connection.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.MailMan;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
response: string;
begin
success := False;
// Demonstrates the MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3
// server and returns the server's response. The second argument is the charset used if the
// command contains non-US-ASCII characters.
mailman := TMailMan.Create;
// Configure the POP3 server connection.
mailman.MailHost := 'pop.example.com';
mailman.MailPort := 995;
mailman.PopSsl := True;
mailman.PopUsername := 'user@example.com';
mailman.PopPassword := 'myPassword';
success := mailman.Pop3BeginSession();
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
// Send the raw POP3 STAT command, which returns the message count and maildrop size.
response := mailman.Pop3SendRawCommand('STAT','us-ascii');
if (mailman.LastMethodSuccess = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
WriteLn('STAT response: ' + response);
success := mailman.Pop3EndSession();
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
mailman.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.