Sample code for 30+ languages & platforms
Android™

Add Multiple To Recipients at Once

See more Email Object Examples

Demonstrates the Chilkat Email.AddMultipleTo method, which parses a comma-separated list of mailbox addresses and appends them all to the direct-recipient (To) list. Each entry may include a display name (e.g. Joe <joe@example.com>). This example adds three To recipients in a single call.

Background: The To header holds a message's primary recipients, and email allows any number of them as a comma-separated list. AddMultipleTo parses that standard syntax — accepting both bare addresses and named forms — so when your recipients arrive as one string (from a form field, database column, or config value) you can populate the whole To list in one step instead of calling AddTo per recipient.

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //  Demonstrates the AddMultipleTo method, which parses a comma-separated list of
    //  addresses and appends them all to the direct-recipient (To) list.

    CkEmail email = new CkEmail();
    email.put_Subject("Multiple To example");
    email.put_From("alice@example.com");

    //  Add several To recipients at once.  Each entry may include a display name.
    email.AddMultipleTo("Joe <joe@example.com>, jane@example.com, Bob <bob@example.com>");

    Log.i(TAG, "NumTo = " + String.valueOf(email.get_NumTo()));

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}