Sample code for 30+ languages & platforms
DataFlex

Add a To Recipient to an Email

See more Email Object Examples

Demonstrates the Chilkat Email.AddTo method, which adds a single direct (To) recipient. The first argument is the friendly display name and the second is the email address. This example adds one To recipient and prints the resulting count.

Background: The To recipients are a message's primary audience — the people it is directly addressed to. Each recipient is stored as a display name plus an email address, which together render in the header as Bob <bob@example.com>. Call AddTo once per recipient, or use AddMultipleTo to add several from a single comma-separated string.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Boolean iSuccess
    Integer iTemp1

    //  Demonstrates the AddTo method, which adds a single direct (To) recipient.
    //  The 1st argument is the friendly (display) name, and the 2nd is the email address.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End
    Set ComSubject Of hoEmail To "AddTo example"
    Set ComFrom Of hoEmail To "alice@example.com"

    Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess

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


End_Procedure