0

I am trying to retrieve email using IMAP in android. I have managed to retrieve the messages from inbox folder, but facing difficulty in parsing them, particularly getting the body part of the message (that I intend to use further in my app).

All I need is a function that takes a message and returns me the plaintext body part (disregarding attachments if possible).

private String getbody(Message message) {           

    try {
        Object m=message.getContent();
    } catch (IOException e) {
        // TODO Auto-generated catch block
            e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return "abc";                // THE BODY PART TO RETURN     

}

I have imported activation.jar file. However using message.getcontent(); is giving me error:

06-20 15:22:50.363: E/AndroidRuntime(9477):     java.lang.RuntimeException: An error occured while executing doInBackground()
06-20 15:22:50.363: E/AndroidRuntime(9477):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.lang.Thread.run(Thread.java:856)
06-20 15:22:50.363: E/AndroidRuntime(9477):     Caused by: java.lang.NoClassDefFoundError: javax.activation.DataHandler
06-20 15:22:50.363: E/AndroidRuntime(9477):     at com.sun.mail.imap.IMAPMessage.getDataHandler(IMAPMessage.java:651)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1420)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at com.example.jmail.MainActivity$NetworkOperation.getbody(MainActivity.java:108)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at com.example.jmail.MainActivity$NetworkOperation.doInBackground(MainActivity.java:87)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at com.example.jmail.MainActivity$NetworkOperation.doInBackground(MainActivity.java:1)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
06-20 15:22:50.363: E/AndroidRuntime(9477):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-20 15:22:50.363: E/AndroidRuntime(9477):     ... 5 more
4

2 回答 2

1

非常感谢您的帮助..终于想通了:)

我长期犯的一个大错误是将 JRE 的 javamail 和 javabeans 激活框架库添加到我的构建路径中。

可以在这里找到专门为 Android 开发的 javamail.jar 和 activation.jar(以及一个附加的.jar)的单独库版本。

于 2013-06-21T21:55:54.807 回答
0

JavaMail FAQ中回答了您的主要问题。

您遇到的错误与此无关。不幸的是,Android 不是 Java,所以它不包含 javax.activation。您需要弄清楚如何将其导入 Android。您可能会在 StackOverflow 的其他地方找到答案。

于 2013-06-21T21:29:46.010 回答