CkJava Requires Chilkat v11.0.0+
CkJava
Create, save, and reopen a plain-text email
See more Email Object Examples
Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.
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("Sam Lee <sam@example.com>");
success = email.AddTo("Alex Rivera","alex@example.net");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
email.put_Subject("Hello");
email.put_Body("This is a plain-text message.");
success = email.SaveEml("message.eml");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
CkEmail received = new CkEmail();
success = received.LoadEml("message.eml");
if (success != true) {
System.out.println(received.lastErrorText());
return;
}
System.out.println(received.ck_from());
System.out.println(received.subject());
System.out.println(received.getPlainTextBody());
}
}