Unicode C++
Unicode C++
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 Unicode C++ Downloads
#include <CkImapW.h>
void ChilkatSample(void)
{
bool success = false;
// 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.
CkImapW imap;
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect(L"imap.example.com");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Login(L"user@example.com",L"myPassword");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.SelectMailbox(L"Inbox");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Enter IDLE mode to monitor the mailbox for changes (new mail, deletions, flag changes).
success = imap.IdleStart();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"IDLE mode started.\n");
// While IDLE is active, no other IMAP command may be sent. End IDLE before doing more work.
success = imap.IdleDone();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}