Sample code for 30+ languages & platforms
Delphi DLL

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
mailman: HCkMailMan;
response: PWideChar;

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 := CkMailMan_Create();

//  Configure the POP3 server connection.
CkMailMan_putMailHost(mailman,'pop.example.com');
CkMailMan_putMailPort(mailman,995);
CkMailMan_putPopSsl(mailman,True);
CkMailMan_putPopUsername(mailman,'user@example.com');
CkMailMan_putPopPassword(mailman,'myPassword');

success := CkMailMan_Pop3BeginSession(mailman);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

//  Send the raw POP3 STAT command, which returns the message count and maildrop size.
response := CkMailMan__pop3SendRawCommand(mailman,'STAT','us-ascii');
if (CkMailMan_getLastMethodSuccess(mailman) = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;
Memo1.Lines.Add('STAT response: ' + response);

success := CkMailMan_Pop3EndSession(mailman);
if (success = False) then
  begin
    Memo1.Lines.Add(CkMailMan__lastErrorText(mailman));
    Exit;
  end;

CkMailMan_Dispose(mailman);