Can't Receive Mails With Pop In Android
I can receive my mails with Imap with this code sample : URLName server = new URLName('imaps://' + username + ':'+ password + '@imap.gmail.com/INBOX'); Session session = Sessio
Solution 1:
First, there's a nice URLName constructor that takes all the component pieces as separate parameters, so you don't have to do string concatenation.
Switch from IMAP to POP3 requires changing the protocol name as well as the host name. See the JavaMail FAQ for examples. The protocol name is "pop3s" and the host name is "pop.gmail.com".
Finally, you should use Session.getInstance instead of Session.getDefaultInstance. Compare the javadocs for the two methods to understand why.
Solution 2:
How about this one.Really worked for me!!(Source:here)
StringSSL_FACTORY="javax.net.ssl.SSLSocketFactory";
Propertiespop3Props=newProperties();
pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
pop3Props.setProperty("mail.pop3.port", "995");
pop3Props.setProperty("mail.pop3.socketFactory.port", "995");
URLNameurl=newURLName("pop3", "pop.gmail.com", 995, "","youremailid@gmail.com",yourpassword);
Sessionsession= Session.getInstance(pop3Props, null);
Storestore=newPOP3SSLStore(session, url);
try {
store.connect();
} catch (MessagingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Folderfolder=null;
try {
folder = store.getDefaultFolder();
folder = folder.getFolder("INBOX");
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (folder == null) {
System.exit(0);
}
try {
folder.open(Folder.READ_ONLY);
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Try retreiving folder via store object.And also mention that the folder you wish to retreive is INBOX!Also note that in settings,port number is 995 form pop.(You may leave the first six lines as they are.)
Post a Comment for "Can't Receive Mails With Pop In Android"