java 读取电子邮件的文本文件转换为 Javamail MimeMessage

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6626722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 16:41:50  来源:igfitidea点击:

Read text file of Email convert to Javamail MimeMessage

javajavamailmime-message

提问by Yottagray

I have a text file of the original source of an email(just straight copied from gmail if you click on "View Original" you'll see it). I want to read this file in and convert it into a MimeMessage.

我有一封电子邮件原始来源的文本文件(如果您单击“查看原始文件”,则直接从 gmail 复制,您会看到它)。我想读入此文件并将其转换为 MimeMessage。

If you are curious as to why, I have JavaMaildir set up, and need to populate it's inbox with emails for testing purposes. I've never really dealt with reading files and all this, so any help would be great thanks.

如果您对原因感到好奇,我已经设置了 JavaMaildir,并且需要用电子邮件填充它的收件箱以进行测试。我从来没有真正处理过阅读文件和所有这些,所以任何帮助都会非常感谢。

回答by Eugene Kuleshov

Something like this should work:

这样的事情应该工作:

InputStream mailFileInputStream = new FileInputStream(...);
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session, mailFileInputStream);
...