Sample code for 30+ languages & platforms
CkJava Requires Chilkat v11.0.0+

Set and read the sender name and address

See more Email Object Examples

Set FromName and FromAddress separately when your application stores them in separate fields. Assign a formatted mailbox to From when that is the input you have. These fields describe the visible author.

Chilkat CkJava Downloads

CkJava
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[])
  {
    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email = new CkEmail();
    email.put_FromName("Workshop team");
    email.put_FromAddress("events@example.com");
    System.out.println("Formatted From: " + email.ck_from());
    //  Parse a formatted mailbox into its two components.
    email.put_From("Alex Rivera <alex@example.net>");
    System.out.println("Name: " + email.fromName());
    System.out.println("Address: " + email.fromAddress());
  }
}