Java
Java
Check Whether an Email Has a Plain-Text Body
See more Email Object Examples
Demonstrates the Chilkat Email.HasPlainTextBody method, which returns true only when a text/plain body is present in the current email object. This example sets a plain-text body and confirms its presence.
Background: The plain-text body is the fallback representation used when HTML is unavailable or unwanted — and the form usually preferred for search, indexing, and accessibility.
HasPlainTextBody is the counterpart to HasHtmlBody; testing both lets a program handle every combination (text-only, HTML-only, both, or neither) gracefully.Chilkat Java 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[])
{
// Demonstrates the HasPlainTextBody method, which returns true only when a text/plain body
// is present in the current email object.
CkEmail email = new CkEmail();
email.put_Subject("HasPlainTextBody example");
email.SetTextBody("Hello, this is the plain-text body.","text/plain");
if (email.HasPlainTextBody() == true) {
System.out.println("The email has a plain-text body.");
}
else {
System.out.println("The email does not have a plain-text body.");
}
}
}