Delphi ActiveX
Delphi ActiveX
Start IMAP IDLE to Monitor a Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.IdleStart method, which sends the IMAP IDLE command to begin listening for unsolicited mailbox updates. It takes no arguments. A mailbox must first be selected, and the server must advertise the IDLE capability.
Background: IDLE is IMAP's push mechanism: instead of polling for new mail, the client tells the server "notify me when something changes," and the server pushes updates as they happen. This is what enables near-instant new-mail alerts. While IDLE is active, no other IMAP command may be sent on that connection — call
IdleDone to leave IDLE before issuing other commands.Chilkat Delphi ActiveX Downloads
var
success: Integer;
imap: TChilkatImap;
begin
success := 0;
// Demonstrates the Imap.IdleStart method, which sends the IMAP IDLE command to begin listening
// for unsolicited mailbox updates. It takes no arguments. A mailbox must be selected and the
// server must advertise the IDLE capability.
imap := TChilkatImap.Create(Self);
imap.Ssl := 1;
imap.Port := 993;
success := imap.Connect('imap.example.com');
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
success := imap.Login('user@example.com','myPassword');
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
success := imap.SelectMailbox('Inbox');
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
// Enter IDLE mode to monitor the mailbox for changes (new mail, deletions, flag changes).
success := imap.IdleStart();
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
Memo1.Lines.Add('IDLE mode started.');
// While IDLE is active, no other IMAP command may be sent. End IDLE before doing more work.
success := imap.IdleDone();
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;
success := imap.Disconnect();
if (success = 0) then
begin
Memo1.Lines.Add(imap.LastErrorText);
Exit;
end;