Java
Chilkat2 Java
MIME Multipart Boundary and Preamble Properties
See more MIME Examples
Demonstrates the Boundary property, which gets or sets the raw boundary token of a multipart entity (without surrounding quotation marks), and UseMmDescription, which controls whether the conventional preamble text is emitted when serializing a multipart entity.
Background. A multipart boundary separates the constituent parts. Chilkat quotes the token automatically in the header when required. The preamble is ignored by MIME-aware readers and is off by default.
Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Mime;
public class ChilkatExample {
public static void main(String[] args) {
Mime mime = new Mime();
// Create a multipart/mixed entity.
try {
mime.newMultipartMixed();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Boundary is the raw boundary token, without surrounding quotation marks. Chilkat quotes it
// automatically in the serialized header when required.
mime.setBoundary("example-boundary");
// UseMmDescription controls whether the conventional preamble text
// "This is a multi-part message in MIME format." is emitted. The default is false.
mime.setUseMmDescription(true);
// Add a simple part so the multipart has content.
Mime part = new Mime();
try {
part.setBodyFromPlainText("First part.");
mime.appendPart(part);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Boundary = " + mime.getBoundary());
String mimeStr;
try {
mimeStr = mime.getMime();
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println(mimeStr);
}
}