Unicode C
Unicode C
Load an Email from MIME Text in a String
See more Email Object Examples
Demonstrates the Chilkat Email.SetFromMimeText method, which loads the email from MIME text (such as the contents of a .eml file) held in a string. On success, it replaces the entire current email. This example serializes one email to MIME with GetMime, then reconstructs it in a second object.
Background: This is the in-memory (string) counterpart to
LoadEml, which reads MIME from a file. It is handy when the raw message text arrives from somewhere other than the filesystem — a database column, an HTTP response, or a message queue — letting you parse it straight into a fully populated Email object.Chilkat Unicode C Downloads
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmailW source;
const wchar_t *mimeText;
HCkEmailW email;
success = FALSE;
// Demonstrates the SetFromMimeText method, which loads the email from MIME text (such as
// the contents of a .eml file) held in a string. On success, it replaces the entire
// current email.
// Build a source email and get its MIME text.
source = CkEmailW_Create();
CkEmailW_putSubject(source,L"Source message");
CkEmailW_putFrom(source,L"alice@example.com");
CkEmailW_putBody(source,L"Hello from MIME text.");
mimeText = CkEmailW_getMime(source);
// Load a new email object from the MIME text.
email = CkEmailW_Create();
success = CkEmailW_SetFromMimeText(email,mimeText);
if (success == FALSE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(source);
CkEmailW_Dispose(email);
return true;
}
wprintf(L"Loaded subject: %s\n",CkEmailW_subject(email));
CkEmailW_Dispose(source);
CkEmailW_Dispose(email);
}