need help on javamail

Hi
i m making a prog to get my mail of my gmail id in my prog
but i am getting only 272 mails..each time
here is the code plz help me out
Thanks


package com.mymail;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Address;
import javax.mail.Store;
import javax.mail.internet.MimeMultipart;

import com.sun.mail.pop3.POP3Store;

public class EmailReceiveTest {

public static void main(String[] args) {

String mailPop3Host = "pop.gmail.com";
String mailStoreType = "pop3";
String mailUser = "mygmail@gmail.com";
String mailPassword = "mypass";
System.out.println("==============================");
receiveEmail(mailPop3Host, mailStoreType, mailUser, mailPassword);
}

public static void receiveEmail(String pop3Host, String storeType, String user, String password)
{
Folder emailFolder;
Store store;
try {
Properties prop = new Properties();

prop.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
prop.setProperty("mail.pop3.socketFactory.fallback", "false");
prop.setProperty("mail.pop3.port", "995");
prop.setProperty("mail.pop3.socketFactory.port", "995");

prop.put("mail.pop3.host", pop3Host);
prop.put("mail.store.protocol", "pop3");
Session session = Session.getInstance(prop,null);
store = (Store) session.getStore("pop3");

System.out.println("your ID is : "+ user);
System.out.println("Connecting...");
store.connect(pop3Host, user, password);
System.out.println("Connected...");
emailFolder = store.getFolder("INBOX");

try {
emailFolder.open(Folder.READ_WRITE);
}
catch (MessagingException ex) {
emailFolder.open(Folder.READ_ONLY);
}
int count = emailFolder.getMessageCount();
System.out.println(count + " total messages");
Message message[] = emailFolder.getMessages();
System.out.println("total:"+message.length);


for (int i=0, n=message.length; i 200)
content = content.substring(0, 200);
System.out.print(content);
}
emailFolder.close(false);
store.close();

} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally
{
System.out.println("in fin");
}

}

}
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories