Domanda

i have setup a POP3 mail server using MailEnable. I am able to send and receive emails via this server using Mozilla Thunderbird but i encounter a strange problem when reading mails with multipart content (in this case a mail with html content) via the JavaMail API. The data returned from the input stream is always only two CR/LF's with a trailing period! Below is the relevant part of my message processing code:

for (Message m : messages) {
    if (m.isMimeType("multipart/*")) {
       System.out.println("Process multipart/* Nachricht");
       Multipart mp = (Multipart) m.getContent();
       Part part = mp.getBodyPart(0);
       System.out.println(part.getContent());
    }
}

There is only one Multipart, so i directly access the first element. Also no nested parts are present in the Multipart. I have no idea which causes the problem and it's getting me mad for a week, so i would be very happy if someone could help me on this issue.

Thanks, fredddmadison

È stato utile?

Soluzione 2

I have found the problem. It was because i had two different implementations of the JavaMail API on my classpath (The apache geronimo 1.4 which was shipped with EclipseLink as well as the JavaMail API reference implementation, 1.5.1). I have now removed the geronimo implementation from the classpath and it works as expected.

Altri suggerimenti

Instead of this

Part part = mp.getBodyPart(0);         // What if there's more parts? Or empty parts?
System.out.println(part.getContent()); // No check for empty String?

I would suggest trying this

mp.writeTo(System.out);                // Use the optimized write.
System.out.flush();                    // Flush the outputstream.

Also, are you sure you're not receiving empty messages?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top