Closed
Description
Hi,
Thanks for this amazing java mailing library.
I would like to ask you if is possible to have any (efficient) way to calculate final message size?
In some scenarios we are checking message size before send it.
Currently, we are doing this by converting Email to MimeMessage and then write it an output stream.
Some like this:
final EmailPopulatingBuilder builder = ....;
final Email message = builder.buildEmail();
try (final CountingOutputStream out = new CountingOutputStream(NullOutputStream.NULL_OUTPUT_STREAM)) {
EmailConverter.emailToMimeMessage(message).writeTo(out);
if (out.getByteCount() > limit) {
//Message bigger than limit
}
}
// Send email
mailer.sendMail(message);
With this solution we are creating MimeMessage twice: one just to check size and other inside mailer.sendEmail.
Do you have any suggestion to calculate this or is possible to (somehow) cache MimeMessage or allow mailer.send(mimeMessage)? Just saying some options.
Thanks in advance.
Best regards,
João Figueiredo.