I don\'t know why I\'m getting the following exception when reading a mail with an attachment file from mail server:
Exception in thread \"main\" javax.mail.
I've just had the same problem. The boundary is specified within the Multipart Content-Type. You can find further information in this source. You can also watch the one of your current Message using the getContentType()
function. In my case I obtained this result:
multipart/mixed; boundary=--boundary_25_2d74d02b-d0d6-4f28-a311-4d1b7d107417
So the getCount()
function uses this boundary to separate all the parts that compose the multiple part. Looks like there could be cases in which this boundary is corrupted.
The mail.mime.multipart.ignoreexistingboundaryparameter System property may be set to true to cause any boundary to be ignored and instead search for a boundary line in the message as with mail.mime.multipart.ignoremissingboundaryparameter.
I followed this instructions and everything works all right. I added the code below:
System.setProperty("mail.mime.multipart.ignoreexistingboundaryparameter", "true");
Hope it helps!
try to set mode on the multipartEntityBuilder ex: multipartEntityBuilder.setMode(HttpMultipartMode.RFC6532);