展开全部
你好,收件箱只拿到4个邮件是因为在你的邮件服务器上62616964757a686964616fe78988e69d8331333361303566只保存了4份邮件。所以只获取到4份。至于内容是空的,可能是你的解析有问题。你尝试一下这个解析方式public static EmailMessage parse(Message message, int comId) {
EmailMessage emailMessage = new EmailMessage();
List attchList = new ArrayList();
try
{
MimeMessageParser parser = new MimeMessageParser(
(MimeMessage) message).parse();
String from = parser.getFrom(); // 获取发件人地址
@SuppressWarnings("unchecked")
List
cc = parser.getCc();// 获取抄送人地址//List
to = parser.getTo(); // 获取收件人地址String subject = parser.getSubject(); // 获取邮件主题
String htmlContent = parser.getHtmlContent(); // 获取Html内容
String plainContent = parser.getPlainContent(); // 获取纯文本邮件内容(注:有些邮件不支持html)
emailMessage.setCc(cc);
emailMessage.setFrom(from);
//emailMessage.setTo(to);
emailMessage.setSubject(subject);
emailMessage.setSendDate(message.getSentDate());
if (Validator.isEmpty(htmlContent))
{
emailMessage.setContent(plainContent);
}
else
{
emailMessage.setContent(htmlContent);
}
@SuppressWarnings("unchecked")
List attachments = parser.getAttachmentList(); // 获取附件,并写入磁盘
if (attachments != null && attachments.size() > 0)
{
String absolutePath = GlobalConfig
.getValue(GlobalConfig.YUN_TEMP_PATH);
String folder = getProFileStoreYunPath(comId);
File file = new File(absolutePath + folder);
if (!file.exists())
{
file.mkdirs();
}
for (DataSource ds : attachments)
{
BufferedOutputStream outStream = null;
BufferedInputStream ins = null;
try
{
String name = ds.getName();
if (name == null)
{
continue;
}
String prefix = name
.substring(0, name.lastIndexOf("."));
String suffix = name
.substring(name.lastIndexOf(".") + 1);
name = prefix + "_" + System.currentTimeMillis() + "."
+ suffix;
String fileName = absolutePath + folder + name;
attchList.add(getProFileStoreYunPath(comId) + name);
outStream = new BufferedOutputStream(
new FileOutputStream(fileName));
ins = new BufferedInputStream(ds.getInputStream());
byte[] data = new byte[1024 * 1024 * 50];
int length = -1;
while ((length = ins.read(data)) != -1)
{
outStream.write(data, 0, length);
}
outStream.flush();
}
finally
{
if (ins != null)
{
ins.close();
}
if (outStream != null)
{
outStream.close();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
// attchList
if (attchList != null && attchList.size() > 0)
{
emailMessage.setAttach(JSON.toJSONString(attchList));
}
return emailMessage;
}
如果还有问题,可以到Java基地上多看看(javajd.com) 另外也可以加如Java基地的qq群