Sample code for 30+ languages & platforms
Java

Get a To Recipient's Full Address

See more Email Object Examples

Demonstrates the Chilkat Email.GetTo method, which returns a To recipient's full email address (display name and address together) at a given zero-based index. This example adds two To recipients and enumerates them.

Background: The To list holds a message's primary recipients. GetTo returns the combined Display Name <address> form; use GetToAddr or GetToName for just the address or name. Iterate from 0 to NumTo - 1 to read the whole recipient list.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  Demonstrates the GetTo method, which returns a To recipient's full email address (name
    //  and address) at the given zero-based index.

    CkEmail email = new CkEmail();
    email.put_Subject("GetTo example");

    email.AddTo("Joe Smith","joe@example.com");
    email.AddTo("Jane Doe","jane@example.com");

    int n = email.get_NumTo();
    int i;
    for (i = 0; i <= n - 1; i++) {
        System.out.println("To " + i + ": " + email.getTo(i));
        }
  }
}