简体   繁体   中英

Java - How to get the raw MIME content of an email (using JavaMail or alternative)

I need to see the raw content of a message - that is, with all the MIME headers and delimeters - and not just the plain text. In other words, the content that you would see if your email client was written before MIME was written. How can I do this via JavaMail (or an alternative)?

UPDATE:

  1. I'm using JavaMail
  2. The MIME is being generated elsewhere - I need to take it as is and send it
  3. I also need to take the raw MIME on incoming email and send it elsewhere, untouched

I'm not sure whether you want to see the raw MIME content of an existing message, or whether you have the raw MIME content and want to do something with it.

For the former, see the MimeMessage.writeTo method.

For the latter, see the MimeMessage constructor that takes an InputStream.

If you already have JavaMail for pulling javax.mail.MimeMessage s off some datastore, you can simply call it's getInputSream() method to access the raw content and ignore the fact that getContent() will conveniently provide a MimeMultiPart object.

If you don't have JavaMail, you probably want to be more specific on your input. Email is all text, so wherever you get it from doesn't matter much as long as you can get an InputStream or a Reader for that source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM