reading mails using java mail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   indrayani_vaze
Posted On:   Saturday, August 2, 2003 01:20 AM

I am trying to read the inbox folder using java mail API. I am using POP3 host. I am specifying pop3 host as mail.accessonline.co.in(the one configured in Miscrosoft outlook). It does not give any exception but it shows me message.length=0

Please suggest a solution

Thanx in advance

Re: reading mails using java mail

Posted By:   Anonymous  
Posted On:   Friday, September 5, 2003 02:49 AM




import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class ReadMail
{
public static void main(String[] args)
{
String host = "sss.com";
String user = "";
String password = "";
try{
Properties properties = System.getProperties();
// properties.put("mail.qic-software.com", );
Session session = Session.getDefaultInstance(properties, null);

Store store = session.getStore("pop3");
// System.out.println("-----> session.getStore <------");
store.connect(host, user, password);
// System.out.println("--> Connection Obtained <---");
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// System.out.println("---> In the InBox Folder <----");
Message[] message = folder.getMessages();
String msg = message.toString();

int count = folder.getMessageCount();
System.out.println("Number of messages ---> " + count);
System.out.println("~~~~~ Message ~~~~~~" );
try{
for(int i = 0; i < message.length; i++){
message[i].writeTo(System.out);
System.out.println("-----------------------------------");
}
}catch(Exception lvObjEx){
System.out.println("Exception : " +lvObjEx.toString());
}
folder.close(false);
System.out.println("------Folder Closed----");
store.close();
}catch(MessagingException MEx){
System.out.println("MessagingException : " +MEx.toString());
}
}
}

About | Sitemap | Contact