Sample code for 30+ languages & platforms
PowerBuilder

Save an Email to a Chilkat XML File

See more Email Object Examples

Demonstrates the Chilkat Email.SaveXml method, which converts the email object to Chilkat's XML representation and saves it to a file. It can later be reloaded with LoadXml. This example builds a message and saves it as XML.

Background: This XML format is an alternative to the standard .eml (MIME) format for persisting an email. Note that .eml also preserves Chilkat's CKX- metadata headers (which are always removed before an email is sent), so it captures the same information. Because .eml is universal and interoperable, Chilkat recommends using SaveEml / LoadEml over the XML format — even within Chilkat-based software.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email

li_Success = 0

//  Demonstrates the SaveXml method, which converts the email object to Chilkat's XML
//  representation and saves it to a file.  It can later be reloaded with LoadXml.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Email.Subject = "Save as XML"
loo_Email.From = "alice@example.com"
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Hello!"

//  Save the email to a Chilkat XML file.
li_Success = loo_Email.SaveXml("qa_output/email.xml")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    return
end if

Write-Debug "Saved to email.xml."

//  Note: The path "qa_output/..." is a relative local filesystem path,
//  relative to the current working directory of the running application.


destroy loo_Email