J'essaie d'obtenir la taille d'un MimeMessage. La méthode getSize() renvoie simplement toujours -1.
Voici mon code :
MimeMessage m = new MimeMessage(session);
m.setFrom(new InternetAddress(fromAddress, true));
m.setRecipient(RecipientType.TO, new InternetAddress(toAddress, true));
m.setSubject(subject);
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent(body, "text/html");
Multipart mp = new MimeMultipart();
mp.addBodyPart(bodyPart);
m.setContent(mp);
m.getSize(); // -1 is returned
VOICI LA RÉPONSE À MA QUESTION :
ByteArrayOutputStream os = new ByteArrayOutputStream();
m.writeTo(os);
int bytes = os.size();