Search code examples
androideclipseemailjakarta-mail

error while trying to receive email using javamail


I tried to receive email from gmail and outlook with IMAP and POP3 in Eclipse (with javamail). But every time I see the same error message.

Receiving using IMAP and 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;

Error log:

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

Using POP3 and 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;

And my error log:

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

I can count the number of received mails but no luck with reading them. I am almost new to android but as far as i can see, there's something wrong with the javamail library.


Solution

  • check mail.jar and activation.jar

    also check this link:

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