message.setTo(Mailbox.parse("Mary Smith <mary@example.net>"));
message.setSubject("An image for you");
// 3) set a multipart body
Multipart multipart = new Multipart("mixed");
// a multipart may have a preamble
multipart.setPreamble("This is a multi-part message in MIME format.");
// first part is text/plain
BodyFactory bodyFactory = new BodyFactory();
BodyPart textPart = createTextPart(bodyFactory, "Why so serious?");
multipart.addBodyPart(textPart);
// second part is image/png (image is created on the fly)
BufferedImage image = renderSampleImage();
BodyPart imagePart = createImagePart(bodyFactory, image);
multipart.addBodyPart(imagePart);
// setMultipart also sets the Content-Type header field
message.setMultipart(multipart);
// 4) print message to standard output