android - 尝试使用 javamail 接收电子邮件时出错

标签 android eclipse email jakarta-mail

我尝试在 Eclipse(使用 javamail)中使用 IMAP 和 POP3 从 gmail 和 outlook 接收电子邮件。但是每次我都看到相同的错误消息。

使用 IMAP 和 Gmail 接收:

Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imap.host", "imap.gmail.com");
props.setProperty("mail.imap.port", "993");
props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imap.socketFactory.fallback", "false");

Session imapSession=Session.getInstance(props);
Store store = imapSession.getStore("imaps");
store.connect("imap.gmail.com","gmail account", "pass");

Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_WRITE);

Message[] msgs =inbox.getMessages();
Message read=msgs[1];
String result=read.toString();
return result;

错误日志:

05-15 20:40:58.822: W/dalvikvm(24130): method Lcom/sun/mail/imap/IMAPStore;.getSession incorrectly overrides package-private method with same name in Ljavax/mail/Service;
05-15 20:40:59.772: I/dalvikvm(24130): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:40:59.772: W/dalvikvm(24130): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:40:59.772: W/dalvikvm(24130): VFY: unable to find class referenced in signature (Ljavax/activation/DataHandler;)
05-15 20:40:59.772: I/dalvikvm(24130): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:40:59.772: W/dalvikvm(24130): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:40:59.772: I/dalvikvm(24130): Could not find method javax.activation.DataHandler.getName, referenced from method javax.mail.internet.MimeUtility.getEncoding
05-15 20:40:59.772: W/dalvikvm(24130): VFY: unable to resolve virtual method 7893: Ljavax/activation/DataHandler;.getName ()Ljava/lang/String;
05-15 20:40:59.772: D/dalvikvm(24130): VFY: replacing opcode 0x6e at 0x0004
05-15 20:41:02.122: I/dalvikvm(24130): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:41:02.122: W/dalvikvm(24130): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:41:02.122: I/dalvikvm(24130): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:41:02.122: W/dalvikvm(24130): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:41:02.122: E/dalvikvm(24130): Could not find class 'javax.activation.DataHandler', referenced from method com.sun.mail.imap.IMAPMessage.getDataHandler
05-15 20:41:02.122: W/dalvikvm(24130): VFY: unable to resolve new-instance 1177 (Ljavax/activation/DataHandler;) in Lcom/sun/mail/imap/IMAPMessage;
05-15 20:41:02.122: D/dalvikvm(24130): VFY: replacing opcode 0x22 at 0x0032
05-15 20:41:02.122: I/dalvikvm(24130): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:41:02.122: W/dalvikvm(24130): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:41:02.122: W/dalvikvm(24130): VFY: unable to find class referenced in signature (Ljavax/activation/DataHandler;)
05-15 20:41:02.192: D/dalvikvm(24130): DexOpt: unable to opt direct call 0x1ec7 at 0x3f in Lcom/sun/mail/imap/IMAPMessage;.getDataHandler

使用 POP3 和 Outlook:

Properties properties = new Properties();
properties.put("mail.pop3.host", "pop-mail.outlook.com");
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");

Session emailSession = Session.getDefaultInstance(properties);

Store store = emailSession.getStore("pop3s");
store.connect("pop-mail.outlook.com", "username", "pass");

Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);   

Message[] messages = emailFolder.getMessages();
String result=messages[10].toString();
emailFolder.close(false);
store.close();
return result;

还有我的错误日志:

05-15 20:30:46.002: W/dalvikvm(21892): method Lcom/sun/mail/pop3/POP3Store;.getSession incorrectly overrides package-private method with same name in Ljavax/mail/Service;
05-15 20:30:49.312: I/dalvikvm(21892): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:30:49.312: W/dalvikvm(21892): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:30:49.312: W/dalvikvm(21892): VFY: unable to find class referenced in signature (Ljavax/activation/DataHandler;)
05-15 20:30:49.312: I/dalvikvm(21892): Failed resolving Ljavax/activation/DataHandler; interface 944 'Ljava/awt/datatransfer/Transferable;'
05-15 20:30:49.312: W/dalvikvm(21892): Link of class 'Ljavax/activation/DataHandler;' failed
05-15 20:30:49.312: I/dalvikvm(21892): Could not find method javax.activation.DataHandler.getContent, referenced from method javax.mail.internet.MimeMessage.getContent
05-15 20:30:49.312: W/dalvikvm(21892): VFY: unable to resolve virtual method 7887: Ljavax/activation/DataHandler;.getContent ()Ljava/lang/Object;
05-15 20:30:49.312: D/dalvikvm(21892): VFY: replacing opcode 0x6e at 0x000b

我可以数出收到的邮件数量,但没法阅读它们。我几乎是 android 的新手,但据我所知,javamail 库有问题。

最佳答案

检查mail.jar和activation.jar

另请检查此链接:

https://code.google.com/p/javamail-android/downloads/list

关于android - 尝试使用 javamail 接收电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30264583/

相关文章:

javascript - 从指令设置表单元素的属性

android - 工具栏后退/主页按钮的 Xamarin 资源 ID 与 Resource.Id.home 不匹配

android - 将Maven与AAR结合使用的Android项目没有Eclipse错误

java - 带有 UTC 时间的进度条

Android:库项目和样式化资源

java - javamail 在发送前将附件加载到内存中吗?

java - addToBackStack() 如何工作?

java - "restricted library"在 Java 中的真正含义是什么?

java - 为什么我会丢失控制台输出?

HTML 电子邮件两列问题