Sample code for 30+ languages & platforms
Unicode C

Load an Email from a Chilkat XML String

See more Email Object Examples

Demonstrates the Chilkat Email.LoadXmlString method, which loads an email from a Chilkat XML representation held in a string, typically obtained from GetXml. On success, the loaded message replaces the entire current email. This example serializes one email to XML, then reconstructs it in a second object.

Background: This is the in-memory (string) counterpart to LoadXml, which reads from a file. Pairing GetXml with LoadXmlString lets you store an email's full state as text in a database column, cache, or message queue, then rebuild the Email object later — without touching the filesystem.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmailW source;
    const wchar_t *xmlStr;
    HCkEmailW email;

    success = FALSE;

    //  Demonstrates the LoadXmlString method, which loads an email from a Chilkat XML string
    //  (typically obtained from GetXml).  On success, the loaded message replaces the entire
    //  current email.

    //  Create an email and serialize it to Chilkat XML (as GetXml would produce).
    source = CkEmailW_Create();
    CkEmailW_putSubject(source,L"Saved email");
    CkEmailW_putFrom(source,L"alice@example.com");
    CkEmailW_putBody(source,L"Hello!");
    xmlStr = CkEmailW_getXml(source);

    //  Load a new email object from the XML string.
    email = CkEmailW_Create();
    success = CkEmailW_LoadXmlString(email,xmlStr);
    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);

    }