views:

276

answers:

1

I am trying to attach a file to an email with Java Mail.

I created a method where you pass a MimeMessage and a File that attaches one to the other.

The problem is when I try call the MimeMessage.getContent() method it will throw a MessagingException as opposed to returning null when there is no content in the message.

Is there a way to check if a message has content rather than catching the exception?

Code I am using:

MimeMultipart multiPart = null;
try
{
    multiPart = mimeMessage.getContent(); // Throws a MessagingException
}
catch (MessagingException e)
{
    multiPart = new MimeMultipart("part");      
}
A: 

Perhaps by checking that getContentType() returns "multipart"

Maurice Perry
It seems to return "text/plain" whether or not the content is set to a multipart object or not.
Gordon