Sample code for 30+ languages & platforms
DataFlex

Convert an Email to Chilkat XML

See more Email Object Examples

Demonstrates the Chilkat Email.GetXml method, which converts the email object to an XML document in memory. The XML is Chilkat's own email-object representation — it is not MIME and not a standardized interchange format. This example builds a message and prints its XML.

Background: This XML form is a Chilkat-specific way to serialize an Email object that can be reloaded with LoadXml / LoadXmlString. Because it is not standard MIME, other mail software cannot read it. In practice the standard .eml format (GetMime / SaveEml) is preferred even within Chilkat-based software: .eml is interoperable and also preserves Chilkat's CKX- metadata headers (which are always removed before an email is sent), so the XML format offers no metadata advantage.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    String sXmlStr

    //  Demonstrates the GetXml method, which converts the email object to an XML document in
    //  memory.  The XML is Chilkat's email-object representation (not MIME and not a
    //  standardized interchange format).

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "GetXml example"
    Set ComFrom Of hoEmail To "alice@example.com"
    Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
    Set ComBody Of hoEmail To "Hello!"

    //  Convert the email to Chilkat's XML representation.
    Get ComGetXml Of hoEmail To sXmlStr
    Showln sXmlStr


End_Procedure