This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
we have developed a Java class to read a mailbox from a mailserver using the javax.mail API. This class reads the unread messages, and exports the email to a .txt file (reads 'from' and 'subject' etc). The attachments of an email are saved individually. Recently however, users have been attachment mails to a mail (attaching a .msg as attachment it seems). It seems like the javax.mail is treating the .msg differently then other attachments (apparently it is reading the attachment-mail as a text format instead of multi-part).
We would like to save the .msg file that is attached to the mail just like other filetypes. I have searched on the internet, but haven't been able to find anything usefull on this matter.
Does anybody have an idea on how to extract .msg-files that are sent as attachments?
If I'm not mistaken, the sample code which comes with the JavaMail download deals with this situation. How does your code differ from that code?
Joined: Mar 23, 2009
Hey David & Paul,
thanks very much for you replies!
@David: I'm affraid using a third-party library is not preferrable, because we already have a production-environment that is using the JavaMail API.
@Paul: I've browsed through the sample code from the JavaMail API, but I'm not able to interpret this to the fullest I'm affraid. Please correct me if I'm not understanding the mail-format correctly, but isn't it so that a mail consists of a message (with from, to etc), and then the "body". I thought that the body consists of either a normal "text" format, or a "multipart" format. I thought that mails with attachments are always "multipart", where the attachment is in a Part of the message. I can't understand why normal files are detected correctly, but a mail as attachment is not interpreted in the same manner.
Please go easy on me, I don't have that much experience in the Java mailing world
Perhaps if you actually ran that sample code on a collection of e-mail messages which you might have at hand, you would get more insight into the possible structure of e-mail messages. It isn't as simple as you thought.
Joined: Mar 23, 2009
ok I'll do that, hopefully it makes some things clear. I've also read the jGuru fundaments of the JavaMail API, clears up some things, but I don't understand it completely yet. I'll run the sample tomorrow and see what it does.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Reading .msg files in an email as attachment