aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Reading .msg files in an email as attachment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Reading .msg files in an email as attachment" Watch "Reading .msg files in an email as attachment" New topic
Author

Reading .msg files in an email as attachment

Eddie Hoeks
Greenhorn

Joined: Mar 23, 2009
Posts: 6
Hello,

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?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use an existing mail library.

http://james.apache.org/mime4j/
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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?
Eddie Hoeks
Greenhorn

Joined: Mar 23, 2009
Posts: 6
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

Regards,

Eddie
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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.
Eddie Hoeks
Greenhorn

Joined: Mar 23, 2009
Posts: 6
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.

Regards,

Eddie
 
jQuery in Action, 2nd edition
 
subject: Reading .msg files in an email as attachment