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