0

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
lost
  • 165
  • 1
  • 4
  • 10
  • 1
    Fix these [common mistakes](http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes). Then post the [session debugging output](http://www.oracle.com/technetwork/java/javamail/faq/index.html#debug). – Bill Shannon Jul 28 '13 at 00:47
  • have you seen this http://stackoverflow.com/questions/2469649/sending-email-failed-to-connect – Freak Jul 28 '13 at 10:11
  • freak i had seen it, it didnt work in my case. @BillShannon yes i applied the fixes but unable to connect. – lost Jul 31 '13 at 03:34
  • So.... Post the debugging output! – Bill Shannon Jul 31 '13 at 18:56
  • @BillShannon it gives C:\Program Files\Java\jdk1.7.0_21\bin\javaw.exe – lost Aug 02 '13 at 19:16
  • That's definitely not the debugging output. Did you follow my link above? – Bill Shannon Aug 03 '13 at 02:01
  • @BillShannon this is the 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** – lost Aug 04 '13 at 09:59
  • All the debug output won't fit in a comment. Edit your original question. – Bill Shannon Aug 05 '13 at 06:46
  • @BillShannon yes edited, but it gives authentication errors too. in fact it throws exception when it tries to connect. although when i telnet "poop.gmail.com"at 995 port it is working fine, it is connecting. – lost Aug 06 '13 at 07:15
  • There should be more debugging output than that. That debugging output only shows the initialization of the POP3 Store, it doesn't show any connection attempts. Try using the [JavaMail msgshow.java demo program](https://java.net/projects/javamail/pages/Home#Samples), [as described in the JavaMail FAQ](http://www.oracle.com/technetwork/java/javamail/faq/index.html#gmail). Does that connect? What does the debugging output from that show? – Bill Shannon Aug 06 '13 at 18:24

0 Answers0