CkJava Requires Chilkat v11.0.0+
CkJava
Offer plain-text and HTML versions of the same message
See more Email Object Examples
Put the same information in two MIME alternatives. A mail reader chooses a representation it supports. Use descriptive link text in HTML and include the destination URL in plain text.
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 registration");
// Both alternatives describe the same invitation.
success = email.AddPlainTextAlternativeBody("Register for the workshop at https://example.com/workshops");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
success = email.AddHtmlAlternativeBody("<p><a href='https://example.com/workshops'>Register for the workshop</a></p>");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
success = email.SaveEml("alternatives.eml");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
System.out.println("Saved alternatives.eml.");
}
}