Sample code for 30+ languages & platforms
Android™

Set the Sender Display Name

See more Email Object Examples

Demonstrates the Chilkat Email.FromName property, which is the display name of the sender. Changing this property updates the display-name portion of the MIME From header while preserving the email address. This example sets the address and display name separately, then reads back the combined From header.

Background: The display name is the friendly label a mail client shows instead of the raw address — for example, showing John Smith rather than john.smith@example.com. It is purely cosmetic and plays no part in message routing; the same address can be paired with any display name. When a display name contains special characters or non-ASCII text, it must be quoted or MIME-encoded in the header, which Chilkat handles for you.

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 Email.FromName property (the name of the sender).
    //  Setting it updates the display-name portion of the From header while
    //  preserving the email address.

    CkEmail email = new CkEmail();

    email.put_FromAddress("john.smith@example.com");
    email.put_FromName("John Smith");

    Log.i(TAG, "FromName = " + email.fromName());
    Log.i(TAG, "From = " + email.ck_from());

  }

  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."
  }
}