CkJava Requires Chilkat v11.0.0+
CkJava
Build a text/watch-html alternative
See more Email Object Examples
Reproduce the three-part layout used by a legacy Watch email integration. Readers can choose plain text or standard HTML when they do not recognize the specialist part. This example demonstrates the MIME layout without assuming current device behavior.
Chilkat CkJava Downloads
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 reminder");
email.put_Body("Your workshop starts at 09:00.");
CkBinData mimeBytes = new CkBinData();
success = email.GetMimeBd(mimeBytes);
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
CkMime mime = new CkMime();
success = mime.LoadMimeBd(mimeBytes);
if (success != true) {
System.out.println(mime.lastErrorText());
return;
}
success = mime.ConvertToMultipartAlt();
if (success != true) {
System.out.println(mime.lastErrorText());
return;
}
// Append the specialist part before the standard HTML fallback.
CkMime special = new CkMime();
special.put_ContentType("text/watch-html");
special.put_Charset("utf-8");
special.SetBody("<b>Workshop at 09:00</b>");
success = mime.AppendPart(special);
if (success != true) {
System.out.println(mime.lastErrorText());
return;
}
CkMime standard = new CkMime();
standard.put_ContentType("text/html");
standard.put_Charset("utf-8");
standard.SetBody("<p>Your workshop starts at <b>09:00</b>.</p>");
success = mime.AppendPart(standard);
if (success != true) {
System.out.println(mime.lastErrorText());
return;
}
success = mime.SaveMime("watch.eml");
if (success != true) {
System.out.println(mime.lastErrorText());
return;
}
System.out.println("Saved watch.eml.");
}
}