Sample code for 30+ languages & platforms
DataFlex

Count the To Recipients of an Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.NumTo property, which is the number of direct "To" recipients. To-recipient indexes are zero-based and can be inspected with GetTo, GetToAddr, and GetToName. This example adds three To recipients and prints the count.

Background: The To header lists the message's primary recipients — the people the email is directly addressed to and expected to act on it. A single email can have any number of To addresses, and each is stored as a display name plus an email address. Together with NumCC and NumBcc, this property lets you inspect the full recipient set of a message.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Integer iTemp1

    //  Demonstrates the read-only Email.NumTo property, which is the number of direct
    //  "To" recipients.  To-recipient indexes are zero-based.

    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 ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess

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


End_Procedure