JavaMail的 - 解析电子邮件内容,似乎无法得到它的工作! (Message.getContent()) [英] JavaMail - Parsing email content, can't seem to get it to work! (Message.getContent())

查看:825
本文介绍了JavaMail的 - 解析电子邮件内容,似乎无法得到它的工作! (Message.getContent())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关的几个星期我一直在开发一个电子邮件客户端Android版,我一直忽略了解析电子邮件内容的一段时间,因为我从来没有能够得到它的工作。因此,时间已经到了求救!

For a few weeks I have been developing a email client for android, I have been ignoring parsing email content for a while as I have never been able to get it to work. Thus, the time has come to ask for help!

我一直在环顾四周,我所遇到的一些方法我都试过,但是从未有过太多的成功!目前,我最亲密的尝试必须是:

I have been looking around and I have come across a few methods I have tried but never had much success with! Currently my closest attempt would have to be:

private String parseContent(Message m) throws Exception
{       
    //Multipart mp = (Multipart)c;
    //int j = mp.getCount();

    /*for (int i = 0; i < mp.getCount(); i++)
    {
        Part part = mp.getBodyPart(i);
        System.out.println(((MimeMessage)m).getContent());
        content = content + part.toString();
        //System.out.println((String)part.getContent());
    }*/

    Object content = m.getContent();
    String contentReturn = null;

    if (content instanceof String) 
    {
        contentReturn = (String) content;
    } 
    else if (content instanceof Multipart) 
    {
        Multipart multipart = (Multipart) content;
        BodyPart part = multipart.getBodyPart(0);
        part.toString();
        contentReturn = part.getContent().toString();
    }   
    return contentReturn;
}

但它不工作,我得到的废话,如javax.mail.internet.MimeMultipart@44f12450。

But it does not work and I get gibberish such as "javax.mail.internet.MimeMultipart@44f12450".

任何人都可以看到我错了?

Can anyone see where I am going wrong?

谢谢, 里斯

推荐答案

以上都不建议是有效的。你不需要在这里做任何事情复杂。的MimeMessage得到了 message.writeTo(OutputStream中);

None of the above suggestions is valid. You don't need to do anything complex here. Mimemessage has got message.writeTo(outputStream);

所有你需要打印的信息是:

All you need to print the message is:

message.writeTo(System.out);

以上code将打印的实际MIME消息到控制台(或者你可以使用任何记录器)。

The above code will print the actual mime message to the console (or you can use any logger).

保存内容的的.eml ,您可以在Outlook中打开它。就这么简单!

Save the content to .eml and you can open it in outlook. Simple as that!

这篇关于JavaMail的 - 解析电子邮件内容,似乎无法得到它的工作! (Message.getContent())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆