sending and receiving emails from gmail with sdk android
I'm been following this link Sending Email in Android using JavaMail API without using the default/built-in app, but it doesn't work for me, that code throw an exception, and if I do a开发者_运维技巧 try..catch, it doesn't catch anything. There is anyone that have tried that code and worked for them? Could you upload a working code for test? When I track the code, the error is after the creation of the DataHandler, I don't know why. I Add external libs, mail, activation, additional, and doesn't work, i don't know what is my problem.
I've found other way to receive emails from gmail or any other email provider.
Properties props = new Properties();
//IMAPS protocol
props.setProperty("mail.store.protocol", "imaps");
//Set host address
props.setProperty("mail.imaps.host", "imaps.gmail.com");
//Set specified port
props.setProperty("mail.imaps.port", "993");
//Using SSL
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
Session imapSession = Session.getInstance(props);
Store store = imapSession.getStore("imaps");
store.connect("imap.gmail.com", usr, password);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_WRITE);
Message[] msgs =inbox.getMessages()
精彩评论