Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Delete a POP3 Message by UIDL

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteByUidl method, which marks the POP3 message identified by a UIDL for deletion. UIDLs are preferred over message numbers because they remain stable across sessions while the message stays in the mailbox. This example marks a message for deletion by its UIDL.

Background: Because a UIDL uniquely and persistently identifies a message, deleting by UIDL is the reliable way to remove exactly the message you intend — even if the mailbox changed since you last looked. As with all POP3 deletion, the message is only marked during the session and is actually removed when the session ends normally (the QUIT command).

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;

begin
  success := False;

  //  Demonstrates the MailMan.DeleteByUidl method, which marks the POP3 message identified by
  //  a UIDL for deletion.  UIDLs are preferred over message numbers because they remain stable
  //  across sessions while the message remains in the mailbox.

  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';

  //  Mark a specific message for deletion by its UIDL.

  success := mailman.DeleteByUidl('0000000123abcdef');
  if (success = False) then
    begin
      WriteLn(mailman.LastErrorText);
      Exit;
    end;

  //  Unless the ImmediateDelete property is set to True, the message is only marked for
  //  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletion
  //  on the server.
  success := mailman.Pop3EndSession();
  if (success = False) then
    begin
      WriteLn(mailman.LastErrorText);
      Exit;
    end;

  WriteLn('Deleted the message from the POP3 server.');

  //  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
  //  connects and authenticates -- using the property settings above -- whenever a server
  //  operation requires it.  Calling the explicit connect/authenticate methods can still be
  //  helpful to determine whether a failure occurs while connecting or while authenticating.


  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.