Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading .msg files in an email as attachment

 
Eddie Hoeks
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an existing mail library.

http://james.apache.org/mime4j/
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic