DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoEmail
Boolean iSuccess
Integer iTemp1
// 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.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "A message"
Set ComBody Of hoEmail To "Some body text."
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Get ComAddStringAttachment Of hoEmail "notes.txt" "Some notes." To iSuccess
Get ComNumTo Of hoEmail To iTemp1
Showln "NumTo before clear = " iTemp1
Get ComNumAttachments Of hoEmail To iTemp1
Showln "NumAttachments before clear = " iTemp1
// Remove all content, resetting the email object.
Send ComClear To hoEmail
Get ComNumTo Of hoEmail To iTemp1
Showln "NumTo after clear = " iTemp1
Get ComNumAttachments Of hoEmail To iTemp1
Showln "NumAttachments after clear = " iTemp1
End_Procedure