// write the XML document and the attachment to the file
po.addPart(xmldocument.getBytes());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, imgtype, baos);
po.addPart(baos.toByteArray());
// write it to a file
// System.out.println("Write "+new File(directory, getFilename()).getAbsolutePath());
po.writeTo(new File(directory, getFilename()));
}