Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate

Unreleased...
Bzip2
LZW
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

Read IMAP Mailbox

Basic Delphi example program showing how to connect to an IMAP server, login, select a mailbox, and fetch the emails one by one.

procedure TForm1.Button1Click(Sender: TObject);
var
  connectSuccess: Integer;
  loginSuccess: Integer;
  selectSuccess: Integer;
  mset: IMessageSet;
  n: Integer;
  i: Integer;
  email: IChilkatEmail2;

begin
  loginSuccess := 0;
  selectSuccess := 0;

  // Import the Chilkat IMAP ActiveX and drop an instance
  // of ChilkatImap onto your Delphi program's form.
  ChilkatImap1.UnlockComponent('anything for 30-day trial');

  // -------------------------
  // Connect to an IMAP server.
  // -------------------------
  connectSuccess := ChilkatImap1.Connect('myImapServerHostname');
  if (connectSuccess = 0) then
    begin
      ShowMessage('Failed to connect!');
      ChilkatImap1.SaveLastError('connectErrorLog.txt');
    end;

  // -------------------------
  // IMAP Login
  // -------------------------
  if (connectSuccess = 1) then
    loginSuccess := ChilkatImap1.Login('myLogin', 'myPassword');

  if (loginSuccess = 0) then
    begin
      ShowMessage('Failed to login!');
      ChilkatImap1.SaveLastError('loginErrorLog.txt');
    end;

  // -------------------------
  // Select an IMAP Mailbox
  // -------------------------
  if (loginSuccess = 1) then
    selectSuccess := ChilkatImap1.SelectMailbox('INBOX');

  if (selectSuccess = 0) then
    begin
      ShowMessage('Failed to select mailbox!');
      ChilkatImap1.SaveLastError('selectErrorLog.txt');
    end;

  if (selectSuccess = 1) then
    begin
      // -------------------------
      // Fetch the complete set of UIDs for the mail in the selected mailbox.
      // -------------------------
      mset := ChilkatImap1.GetAllUids();
      if (mset = nil) then
        begin
          ShowMessage('Failed to fetch Uids');
          ChilkatImap1.SaveLastError('getUidsErrorLog.txt');
        end
      else
        begin
          // For each UID, fetch the email and display the FROM and Subject
          n := mset.Count;

          for i := 0 to n-1 do
            begin
              email := ChilkatImap1.FetchSingle(mset.GetID(i),1);
              if (email <> nil) then
                begin
                    Memo1.Lines.Add(email.From);
                    Memo1.Lines.Add(email.Subject);
                    Memo1.Lines.Add('----');
                end;
            end;
        end;

    end;

    ShowMessage('Finished!');
end;

 

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser