Unicode C
Unicode C
Append a MIME Message to an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMime method, which uploads a complete RFC 822/MIME message to a mailbox. The first argument is the destination mailbox name and the second is the MIME text. This example obtains the MIME from an Email object and uploads it to Drafts.
Background: Use
AppendMime when you already hold a message's raw source — a .eml file, a message you assembled, or one you received. Chilkat sends the text exactly as supplied, without normalizing line endings or re-encoding headers, so every header and MIME boundary is preserved verbatim. The supplied text must be plain text (no raw non-text binary bytes).Chilkat Unicode C Downloads
#include <C_CkImapW.h>
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkImapW imap;
HCkEmailW email;
const wchar_t *mimeText;
success = FALSE;
// Demonstrates the Imap.AppendMime method, which uploads a complete MIME message to a mailbox.
// The 1st argument is the destination mailbox name and the 2nd is the MIME text.
imap = CkImapW_Create();
CkImapW_putSsl(imap,TRUE);
CkImapW_putPort(imap,993);
success = CkImapW_Connect(imap,L"imap.example.com");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
success = CkImapW_Login(imap,L"user@example.com",L"myPassword");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
// Build the email to be uploaded.
email = CkEmailW_Create();
CkEmailW_putSubject(email,L"Meeting agenda");
CkEmailW_putFrom(email,L"Alice <alice@example.com>");
success = CkEmailW_AddTo(email,L"Bob",L"bob@example.com");
CkEmailW_putBody(email,L"Let's meet at 10am to review the agenda.");
// Obtain the MIME text to upload. Here it is generated from the Email, but it could equally
// be read from a .eml file.
mimeText = CkEmailW_getMime(email);
if (CkEmailW_getLastMethodSuccess(email) == FALSE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
return;
}
// Append (upload) the MIME to the "Drafts" mailbox.
success = CkImapW_AppendMime(imap,L"Drafts",mimeText);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
return;
}
wprintf(L"Appended UID: %d\n",CkImapW_getAppendUid(imap));
success = CkImapW_Disconnect(imap);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
return;
}
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
}