CkJava Requires Chilkat v11.0.0+
CkJava
Attach an existing EML as a message/rfc822 part
See more Email Object Examples
Load the saved message and attach a copy as a nested email. Recipients can open the nested headers, bodies, and attachments. Using an Email object avoids native byte-array differences across languages.
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 original = new CkEmail();
success = original.LoadEml("message.eml");
if (success != true) {
System.out.println(original.lastErrorText());
return;
}
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("Registration correspondence");
email.put_Body("The original message is attached for reference.");
success = email.AttachEmail(original);
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
System.out.println("Nested messages: " + email.get_NumAttachedMessages());
success = email.SaveEml("correspondence.eml");
if (success != true) {
System.out.println(email.lastErrorText());
return;
}
System.out.println("Saved correspondence.eml.");
}
}