Java电子邮件消息解析器? [英] Java Email message Parser?
问题描述
是否有人熟悉有助于解析以下电子邮件字段(日期、主题、发件人、收件人)的 Java 库?
Is anyone familiar with a Java library that helps with parsing the fields (date, subject, from, to) of the email below?
Message-ID: <19815303.1075861029555.JavaMail.ss@kk>
Date: Wed, 6 Mar 2010 12:32:20 -0800 (PST)
From: someone@someotherplace.com
To: someone@someplace.com
Subject: some subject
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-From: one, some <some.one@someotherplace.com>
X-To: one
X-cc:
X-bcc:
X-Folder: BobInbox
X-Origin: Bob-R
X-FileName: rbob (Non-Privileged).pst
some message
推荐答案
JavaMail 是一个 oracle 库,它在 javax.mail 包中提供邮件服务和邮件相关服务(如解析常规和 MIME 消息).此外,Apache 有一个用于邮件处理的 Commons Email 库.
JavaMail is an oracle library that provides mail services and mail related services (like parsing conventional & MIME messages) in the javax.mail package. Additionally Apache has a Commons Email library for mail handling.
在 JavaMail api 中,解析包含电子邮件消息(可能是也可能不是明确的 MIME)的字符串的简单方法如下
In the JavaMail api, a simple way to parse a string containing an email message (which may or may not be explicitly MIME) would be as follows
String content = ...
Session s = Session.getInstance(new Properties());
InputStream is = new ByteArrayInputStream(content.getBytes());
MimeMessage message = new MimeMessage(s, is);
可以像这样解析标题
message.getAllHeaderLines();
for (Enumeration<Header> e = message.getAllHeaders(); e.hasMoreElements();) {
Header h = e.nextElement();
h.getName();
h.getValue();
}
这篇关于Java电子邮件消息解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!