Mails Receiving
Dear all,
Greets for the Day.
I am here by sending a java program to receive a mails from my inbox but if i run it i am getting the following error.Please help me to rectify the problem and get the result.Thanks for your help.
Regards,
Rajesh.
Program is
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
/**
* @author rajesh
*
*/
public class MainClass {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Properties props=new Properties();
String host="192.168.0.222";
String provider="pop3";
Session session=Session.getDefaultInstance(props,new MailAuthenticator());
Store store=session.getStore(provider);
//store.connect(host,null, null);
store.connect(host, provider,"mail.smtp.host");
Folder inbox=store.getFolder("INBOX");
if(inbox==null){
System.out.println("NO INBOX");
System.exit(1);
}
inbox.open(Folder.READ_ONLY);
Message[] messages=inbox.getMessages();
for(int i=0;i<messages.length;i++){
System.out.println("Message "+(i+1));
messages.writeTo(System.out);
}
inbox.close(false);
store.close();
}
}
class MailAuthenticator extends Authenticator{
public MailAuthenticator(){
}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("rajesh","vetula");
}
}
Error getting is :
Exception in thread "main" javax.mail.AuthenticationFailedException: EOF on socket
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:146)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at MainClass.main(MainClass.java:28)>

