How do I restrict the size of the Mail attachment to be sent? For example, I want to sent a document only if its size less <= 300K.

John Zukowski

When creating the mail message to send, check the size of the attachment before 'attaching'. If it is too large, don't attach it. There is nothing that is part of the JavaMail API to limit this for you, though you're SMTP server might reject the message if too large.

Keep in mind that the attachment size is the 7-bit encoded size, not necessarily the original 8-bit encoded size. The Part interface has a getSize() method so you can find out its size.