The server might declare the maximum message size it accepts using the SMTP SIZE extension.
You can query for the value using:
That's the total size of a message. Note that not all servers will return this information, even
though they might enforce a limit.
Computing the actual size of a message can be expensive.
The simplest approach is something like this:
CountingOutputStream cos = new CountingOutputStream();
int size = cos.getSize();
CRLFOutputStream is in the JavaMail download bundle in the demo directory.
You have to write CountingOutputStream by subclassing OutputStream and counting the
number of bytes written without doing anything with them.
I told you how to do both - find the maximum size the server allows (SMTP SIZE parameter)
and compute the size of a message you have, e.g., to see if it's less than the maximum size
allowed by the server.