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

Choose the character set for an HTML email

See more Email Object Examples

Read a UTF-8 HTML file as Unicode, then set the charset Chilkat will use when writing the MIME text. The HTML file’s input encoding and the message’s output charset are separate choices. UTF-8 can represent names from multiple writing systems.

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[])
  {
    boolean success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email = new CkEmail();
    email.put_From("Workshop team <events@example.com>");
    success = email.AddTo("Alex Rivera","alex@example.net");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    email.put_Subject("Workshop registration");
    CkStringBuilder html = new CkStringBuilder();
    success = html.LoadFile("newsletter.html","utf-8");
    if (success != true) {
        System.out.println("Failed: html.LoadFile.");
        return;
        }

    email.put_Charset("utf-8");
    email.SetHtmlBody(html.getAsString());

    success = email.SaveEml("newsletter.eml");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

    System.out.println("Saved newsletter.eml.");
  }
}