我試圖在android中使用IMAP檢索電子郵件。我設法從收件箱文件夾中檢索郵件,但是在解析它們時遇到困難,特別是收到郵件的正文部分(我打算在我的應用中進一步使用)。在Android中解析javamail消息以獲取正文部分
我需要的是一個函數,它接收一條消息並返回明文正文部分(如果可能,不考慮附件)。
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
}
我有進口的activation.jar文件。但是使用message.getcontent()
;給我錯誤:
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
非常感謝您的幫助..終於想通了:) –