// изменить размер
File oldpic = new File(filepatch);
img = ImageIO.read(oldpic);
double aspectRatio = (double) img.getWidth(null)/(double) img.getHeight(null);
tempJPG = resizeImage(img, 164, (int) (173/aspectRatio));
filepatch_new=filepatch+".jpg";
newFileJPG = new File(filepatch_new);
ImageIO.write(tempJPG, "jpg", newFileJPG);
String filepatch_new_old=filepatch+"_old.jpg";
File newFileOldJPG = new File(filepatch_new_old);
ImageIO.write(ImageIO.read(oldpic), "jpg", newFileOldJPG);
// MIME mini
Stream stream = ses.createStream();
// Do not convert MIME to rich text
ses.setConvertMIME(false);
if (docR.hasItem("Body")){
docR.removeItem("Body");
}
MIMEEntity body = docR.createMIMEEntity();
if (stream.open(newFileJPG.getPath(), "binary")) {
if (stream.getBytes() != 0) {
body.setContentFromBytes(stream, "image/jpeg", MIMEEntity.ENC_IDENTITY_BINARY);
}
else System.out.println(newFileJPG.getPath());
}
else System.out.println("Error opening "+newFileJPG.getPath());
stream.close();
// Restore conversion
ses.setConvertMIME(true);
// приатачить full photo
if (docR.hasItem("bodyfull")){
docR.removeItem("bodyfull");
}
RichTextItem bodyfull = docR.createRichTextItem("bodyfull");
bodyfull.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, newFileOldJPG.getPath(), newFileOldJPG.getName());
docR.save(true, true);
body.recycle();
bodyfull.recycle();
docR.recycle();