In fact I am trying to get emails through Gmail POP3, I enabled POP3 protocol in gmail but established a session and connection over SSL but I am an exception and unable to figure it out what is the actual matter behind. here is the exception
Exception in thread "main" javax.mail.AuthenticationFailedException: failed to connect
at javax.mail.Service.connect(Service.java:382)
at javax.mail.Service.connect(Service.java:226)
at javax.mail.Service.connect(Service.java:246)
at EmailReciever.getEmail(EmailReciever.java:47)
at TestEmailReceiver.main(TestEmailReceiver.java:14)
and the I connected it as like
public void getEmail(String host, String port, final String userName, final String password)
throws MessagingException, IOException {
// sets POP3 properties
Properties properties = new Properties();
properties.put("mail.pop3.com", host);
properties.put("mail.pop3.port", port);
properties.put("mail.pop3.auth", "true");
// sets POP3S properties
properties.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.pop3.socketFactory.fallback", "false");
properties.setProperty("mail.pop3.socketFactory.port", "995");
Session session = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
});
please help!
here is my debugging output...
DEBUG: setDebug: JavaMail version 1.5.0
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]
DEBUG POP3: mail.pop3.rsetbeforequit: false
DEBUG POP3: mail.pop3.disabletop: false
DEBUG POP3: mail.pop3.forgettopheaders: false
DEBUG POP3: mail.pop3.cachewriteto: false
DEBUG POP3: mail.pop3.filecache.enable: false
DEBUG POP3: mail.pop3.keepmessagecontent: false
DEBUG POP3: mail.pop3.starttls.enable: false
DEBUG POP3: mail.pop3.starttls.required: false