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

时间:2015-05-15 16:37:05

标签: android eclipse email javamail

我试图通过Eclipse中的IMAP和POP3(使用javamail)接收来自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库出了问题。

1 个答案:

答案 0 :(得分:1)

检查mail.jar和activation.jar

还要检查此链接:

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