Delphi Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Delphi Examples

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

More Examples...
Amazon S3
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

Type Conversion

 

Article: Understanding COM References in Delphi

How to Process a Large IMAP Mailbox

Download Chilkat Email ActiveX

Demonstrates how to process a mailbox containing a large number of emails. This example was prompted by a Chilkat customer who needed to efficiently process a mailbox with over 100,000 emails. The technique is to first select the mailbox, which updates the imap.NumMessages property to reflect the number of messages in the mailbox. The emails in the mailbox have sequence numbers ranging from 1 to NumMessages. Two new methods, FetchSequence and FetchSequenceHeaders, can then be used to fetch emails based on sequence number ranges.

Download 32-bit Chilkat IMAP ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls,
    CHILKATMAILLib2_TLB,
    CHILKATIMAPLib_TLB,
    OleCtrls;

...

procedure TForm1.Button1Click(Sender: TObject);
var
imap: TChilkatImap;
success: Integer;
bundle: CHILKATIMAPLib_TLB.IChilkatEmailBundle2;
startSeqNum: Integer;
numToFetch: Integer;
i: Integer;
email: CHILKATMAILLib2_TLB.IChilkatEmail2;

begin
imap := TChilkatImap.Create(Self);

//  Anything unlocks the component and begins a fully-functional 30-day trial.
success := imap.UnlockComponent('Anything for 30-day trial');
if (success <> 1) then
  begin
    ShowMessage(imap.LastErrorText);
    Exit;
  end;

//  Connect to an IMAP server.
success := imap.Connect('mail.chilkatsoft.com');
if (success <> 1) then
  begin
    ShowMessage(imap.LastErrorText);
    Exit;
  end;

//  Login
success := imap.Login('myLogin','myPassword');
if (success <> 1) then
  begin
    ShowMessage(imap.LastErrorText);
    Exit;
  end;

//  Our experience has been that with some IMAP servers,
//  the response time for selecting a mailbox increases with
//  the size of the mailbox.  You may need to increase the
//  ReadTimeout to a value larger than the default of 30 seconds.
//  In this case, it is set to 60 seconds.
imap.ReadTimeout := 60;

//  Select an IMAP mailbox
success := imap.SelectMailbox('Inbox');
if (success <> 1) then
  begin
    ShowMessage(imap.LastErrorText);
    Exit;
  end;

//  After selecting a mailbox, the NumMessages property will
//  be updated to reflect the total number of emails in the mailbox:
Memo1.Lines.Add(IntToStr(imap.NumMessages));

//  The emails in the mailbox will always have sequence numbers
//  ranging from 1 to NumMessages.  There are two new methods
//  that can be called to fetch emails for a range of sequence
//  numbers: FetchSequence and FetchSequenceHeaders.
//  They are identical except one returns full emails whereas
//  the other returns headers-only.

//  This example assumes there are more than 10 emails in the
//  mailbox and fetches the 1st 10 emails:

startSeqNum := 1;
numToFetch := 10;
bundle := imap.FetchSequence(startSeqNum,numToFetch);
if (bundle = nil ) then
  begin
    ShowMessage(imap.LastErrorText);
    Exit;
  end;

//  Print the From and Subject of each email:

for i := 0 to bundle.MessageCount - 1 do
  begin

    //  GetEmail does not communication with the IMAP server.
    //  It simply extracts a single email from the in-memory bundle.
    email := bundle.GetEmail(i) As CHILKATMAILLib2_TLB.IChilkatEmail2;

    Memo1.Lines.Add(email.From);
    Memo1.Lines.Add(email.Subject);

    Memo1.Lines.Add('--');

  end;

//  Disconnect from the IMAP server.
imap.Disconnect();


end;

 

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

Mail Component · .NET Email Component · XML Parser