Sample code for 30+ languages & platforms
PowerBuilder

Clear an Email Object

See more Email Object Examples

Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.

Background: Reusing a single Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Email

//  Demonstrates the Clear method, which removes the current message content, including
//  recipients, headers, body representations, attachments, related items, and embedded
//  messages -- leaving an empty email object.

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 = "A message"
loo_Email.Body = "Some body text."
loo_Email.AddTo("Bob","bob@example.com")
loo_Email.AddStringAttachment("notes.txt","Some notes.")

Write-Debug "NumTo before clear = " + string(loo_Email.NumTo)
Write-Debug "NumAttachments before clear = " + string(loo_Email.NumAttachments)

//  Remove all content, resetting the email object.
loo_Email.Clear()

Write-Debug "NumTo after clear = " + string(loo_Email.NumTo)
Write-Debug "NumAttachments after clear = " + string(loo_Email.NumAttachments)


destroy loo_Email