Java
Java
Serialize MIME to a String
See more MIME Examples
Demonstrates the Chilkat Mime.GetMime method, which serializes and returns the complete MIME entity — headers, body, multipart boundaries, and all descendants — as a string. It takes no arguments.
Background: This produces the finished MIME text ready to send, store, or hand to another component — the inverse of loading. The whole tree is emitted, including generated multipart boundaries. Because it returns a string, it is best for text-safe content; when the body may contain raw binary bytes, serialize with
GetMimeBd to a BinData instead so nothing is altered.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[])
{
boolean success = false;
// Demonstrates the Mime.GetMime method, which serializes and returns the complete MIME entity
// (headers, body, multipart boundaries, and all descendants) as a string. It takes no
// arguments.
CkMime mime = new CkMime();
// Build a simple MIME entity.
success = mime.SetBodyFromPlainText("Hello, this is the message body.");
if (success == false) {
System.out.println(mime.lastErrorText());
return;
}
// Serialize it to a string.
String mimeText = mime.getMime();
if (mime.get_LastMethodSuccess() == false) {
System.out.println(mime.lastErrorText());
return;
}
System.out.println(mimeText);
}
}