How to Pop Mails from Gmail Server.. code not working..
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kesavan_E
Posted On:   Wednesday, September 21, 2005 02:02 AM

Hi, I wrote a java class to pop the mail from gmail account And its not working. See the below code. And give me your suggestions. I have also enabled pop in my gmail account... import javax.mail.*; import javax.mail.internet.*; import java.util.*; import java.io.*; public class POP3Client { public static void main(String[] args) { Properties props = new Properties(); String host = "pop.gmail.com"; String username = "nglkesavan"; String password = "noorul"; String provider = "pop3"; try {    More>>

Hi,
I wrote a java class to pop the mail from gmail account And its not working. See the below code. And give me your suggestions. I have also enabled pop in my gmail account...



import javax.mail.*;


import javax.mail.internet.*;


import java.util.*;


import java.io.*;



public class POP3Client {


public static void main(String[] args) {


Properties props = new Properties();


String host = "pop.gmail.com";

String username = "nglkesavan";

String password = "noorul";

String provider = "pop3";



try {



// Connect to the POP3 server

Session session = Session.getDefaultInstance(props, null);

Store store = session.getStore(provider);

store.connect(host, username, password);



// Open the folder

Folder inbox = store.getFolder("Inbox");

if (inbox == null) {

System.out.println("No INBOX");

System.exit(1);

}

inbox.open(Folder.READ_ONLY);



// Get the messages from the server

Message[] messages = inbox.getMessages();

for (int i = 0; i < messages.length; i++) {

System.out.println("------------ Message " + (i+1) + " ------------");

messages[i].writeTo(System.out);

}

// Close the connection

// but don't remove the messages from the server

inbox.close(false);

store.close();

}

catch (Exception ex) {

ex.printStackTrace();

}

}

}



______________________________________________________________________________________________________________________
ITS THROWING BELOW EXCEPTION:

javax.mail.AuthenticationFailedException: EOF on socket

at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:128)

at javax.mail.Service.connect(Service.java:236)

at javax.mail.Service.connect(Service.java:137)

at POP3Client.main(POP3Client.java:22)

___________________________________________________________
please tell me requirements and send me the corrections to be made in the code

   <<Less

How to Pop Mails from Gmail Server.. code not working..

Posted By:   Naga_Raju  
Posted On:   Thursday, November 24, 2005 07:30 AM

hi friend,
I also faced this kind of problem with Gmail.
Reason for this is Gmail is more secure than the others.
Gmail using SSL Factory(SecureSocketLayer) to secure their
Mail users.
For this reason you have to first authenticate with the
Gmail pop3 server using SSL.In that class you will get
a class named Authenticator.Using this call u can
authenticate yourself to Gmail.

try this code:
***************

import com.sun.mail.pop3.POP3SSLStore;
import javax.mail.URLName;


try{
Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3.user", args[1]);
pop3Props.setProperty("mail.pop3.passwd", args[2]);
pop3Props.setProperty("mail.pop3.ssl", "true");
pop3Props.setProperty("mail.pop3.host", args[0]);

Session session = null;
Store store = null;

String user = ((pop3Props.getProperty("mail.pop3.user") != null) ? pop3Props.getProperty("mail.pop3.user") : pop3Props.getProperty("mail.user"));
String passwd = ((pop3Props.getProperty("mail.pop3.passwd") != null) ? pop3Props.getProperty("mail.pop3.passwd") : pop3Props.getProperty("mail.passwd"));
String host = ((pop3Props.getProperty("mail.pop3.host") != null) ? pop3Props.getProperty("mail.pop3.host") : pop3Props.getProperty("mail.host"));



if((pop3Props.getProperty("mail.pop3.ssl") != null) && (pop3Props.getProperty("mail.pop3.ssl").equalsIgnoreCase("true"))){
String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
String portStr = ((pop3Props.getProperty("mail.pop3.port") != null) ? pop3Props.getProperty("mail.pop3.port") : "995");
pop3Props.setProperty("mail.pop3.port", portStr);
pop3Props.setProperty("mail.pop3.socketFactory.port", portStr);


URLName url = new URLName("pop3://"+user+":"+passwd+"@"+host+":"+pop3Props.getProperty("mail.pop3.port"));

session = Session.getInstance(pop3Props, null);
store = new POP3SSLStore(session, url);
}
else{
session = Session.getInstance(pop3Props, null);
store = session.getStore("pop3");
}
//session.setDebug(true);

store.connect(host,user, passwd);



try this code you will definetely get the solution.


Regards
*******

Nagaraju G

Re: How to Pop Mails from Gmail Server.. code not working..

Posted By:   WarnerJan_Veldhuis  
Posted On:   Wednesday, September 21, 2005 10:46 AM

Errmm... It would be a bad idea to supply your username and password of your gmail account to the world... It's advisable to update your profile asap...
About | Sitemap | Contact