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

Fetch a POP3 Message's Raw MIME by Message Number

See more POP3 Examples

Demonstrates the Chilkat MailMan.FetchMimeByMsgnumBd method, which retrieves an email by POP3 message number and stores the raw MIME source bytes in a BinData. Chilkat clears the BinData before downloading. This example fetches message number 1's MIME into a BinData.

Background: This is the message-number variant of FetchMimeBd. It grabs the untouched MIME bytes of a message identified by its 1-based session position — handy when iterating a mailbox by number and archiving or forwarding each message's exact source. Keep in mind message numbers are only valid within the current session, so for stable identification across sessions prefer the UIDL-based FetchMimeBd.

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,
  Chilkat.BinData;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  mailman: TMailMan;
  bdMime: TBinData;

begin
  success := False;

  //  Demonstrates the MailMan.FetchMimeByMsgnumBd method, which retrieves an email by POP3
  //  message number and stores the raw MIME source bytes in a BinData.  Chilkat clears the
  //  BinData before downloading.

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

  //  Fetch the raw MIME of message number 1 into a BinData.
  bdMime := TBinData.Create;

  success := mailman.FetchMimeByMsgnumBd(1,bdMime);
  if (success = False) then
    begin
      WriteLn(mailman.LastErrorText);
      Exit;
    end;

  WriteLn('MIME size (bytes) = ' + bdMime.NumBytes);

  //  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;
  bdMime.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.