Sample code for 30+ languages & platforms
DataFlex

Clear the To Recipients of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.ClearTo method, which clears the list of direct (To) recipients. It changes only the current in-memory email object and does not affect messages already sent. This example adds two To recipients, clears them, and prints the count before and after.

Background: The To list holds a message's primary recipients. When reusing one Email object as a template across multiple sends, ClearTo wipes just that list so each send addresses the right people, without disturbing the subject, body, or attachments. It pairs with ClearCC and ClearBcc for full control over the recipient lists.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Integer iTemp1

    //  Demonstrates the ClearTo method, which clears the list of direct (To) recipients.
    //  This changes only the current email object.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get ComAddTo Of hoEmail "Joe" "joe@example.com" To iSuccess
    Get ComAddTo Of hoEmail "Jane" "jane@example.com" To iSuccess
    Get ComNumTo Of hoEmail To iTemp1
    Showln "NumTo before clear = " iTemp1

    //  Remove all To recipients.
    Send ComClearTo To hoEmail

    Get ComNumTo Of hoEmail To iTemp1
    Showln "NumTo after clear = " iTemp1


End_Procedure