Unicode C++
Unicode C++
Append MIME with Initial IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its initial system flags. The first argument is the mailbox and the second is the MIME text. The third through sixth arguments control \Seen, \Flagged, \Answered, and \Draft respectively — pass true to set a flag. This example uploads a message that is already marked read.
Background: When importing or archiving mail you frequently want the uploaded message to arrive in a particular state — already read, pre-flagged, or marked as a draft. Setting the flags at append time is a single operation, avoiding a second
STORE round trip. These explicit arguments take precedence over the AppendSeen property.Chilkat Unicode C++ Downloads
#include <CkImapW.h>
#include <CkEmailW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its
// initial system flags. The 1st argument is the mailbox, the 2nd is the MIME text, and the
// 3rd through 6th arguments set the \Seen, \Flagged, \Answered, and \Draft flags.
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;
}
// Build the email to be uploaded.
CkEmailW email;
email.put_Subject(L"Meeting agenda");
email.put_From(L"Alice <alice@example.com>");
success = email.AddTo(L"Bob",L"bob@example.com");
email.put_Body(L"Let's meet at 10am to review the agenda.");
const wchar_t *mimeText = email.getMime();
if (email.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
// Choose the initial flags. Named variables make each argument's meaning clear at the call.
bool seen = true;
bool flagged = false;
bool answered = false;
bool draft = false;
// Upload to the Inbox already marked as read (\Seen), with the other flags unset.
success = imap.AppendMimeWithFlags(L"Inbox",mimeText,seen,flagged,answered,draft);
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"Appended UID: %d\n",imap.get_AppendUid());
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}