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");
}