Sample code for 30+ languages & platforms
PureBasic

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 PureBasic Downloads

PureBasic
IncludeFile "CkEmail.pb"

Procedure ChilkatExample()

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

    email.i = CkEmail::ckCreate()
    If email.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkEmail::ckAddTo(email,"Joe","joe@example.com")
    CkEmail::ckAddTo(email,"Jane","jane@example.com")
    CkEmail::ckAddTo(email,"Bob","bob@example.com")

    Debug "NumTo = " + Str(CkEmail::ckNumTo(email))


    CkEmail::ckDispose(email)


    ProcedureReturn
EndProcedure