简体   繁体   English

Java - 如何获取电子邮件的原始MIME内容(使用JavaMail或替代方案)

[英]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. 我需要查看邮件的原始内容 - 即所有MIME标头和分隔符 - 而不仅仅是纯文本。 In other words, the content that you would see if your email client was written before MIME was written. 换句话说,如果您的电子邮件客户端是在编写MIME之前编写的,您将看到的内容。 How can I do this via JavaMail (or an alternative)? 我怎么能通过JavaMail(或替代)来做到这一点?

UPDATE: 更新:

  1. I'm using JavaMail 我正在使用JavaMail
  2. The MIME is being generated elsewhere - I need to take it as is and send it MIME在其他地方生成 - 我需要按原样并发送它
  3. I also need to take the raw MIME on incoming email and send it elsewhere, untouched 我还需要在传入的电子邮件中使用原始MIME并将其发送到其他地方,不受影响

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. 我不确定您是否要查看现有邮件的原始MIME内容,或者您​​是否拥有原始MIME内容并希望对其执行某些操作。

For the former, see the MimeMessage.writeTo method. 对于前者,请参阅MimeMessage.writeTo方法。

For the latter, see the MimeMessage constructor that takes an InputStream. 对于后者,请参阅采用InputStream的MimeMessage构造函数。

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. 如果您已经有JavaMail用于从某些数据存储中提取javax.mail.MimeMessage ,则可以简单地调用它的getInputSream()方法来访问原始内容,并忽略getContent()将方便地提供MimeMultiPart对象的MimeMultiPart

If you don't have JavaMail, you probably want to be more specific on your input. 如果您没有JavaMail,您可能希望更具体地了解您的输入。 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. 电子邮件是所有文本,因此无论您从何处获取它都无关紧要,只要您可以获得该源的InputStreamReader

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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