Unicode C++
Unicode C++
Append MIME from a StringBuilder with Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a StringBuilder and sets its initial system flags. The first argument is the mailbox, the second is the StringBuilder, and the third through sixth set \Seen, \Flagged, \Answered, and \Draft. This example uploads to Drafts with the draft flag set.
Background: This is the
StringBuilder form of AppendMimeWithFlags. Passing the MIME as a StringBuilder avoids copying a large message into an intermediate string and is convenient when you already built or loaded the message into a StringBuilder (for example with LoadFile).Chilkat Unicode C++ Downloads
#include <CkImapW.h>
#include <CkEmailW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a
// StringBuilder and sets its initial system flags. The 1st argument is the mailbox, the 2nd
// is the StringBuilder, and the 3rd through 6th set \Seen, \Flagged, \Answered, and \Draft.
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;
}
// Load the MIME into a StringBuilder. (A StringBuilder can also be filled via LoadFile.)
CkStringBuilderW sbMime;
sbMime.Append(mimeText);
// Choose the initial flags. Named variables make each argument's meaning clear at the call.
bool seen = false;
bool flagged = false;
bool answered = false;
bool draft = true;
// Upload to "Drafts" with the \Draft flag set.
success = imap.AppendMimeWithFlagsSb(L"Drafts",sbMime,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;
}
}