How to read the message body in a mail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Srinivas_Velivela
Posted On:   Tuesday, October 16, 2001 05:51 AM

how can we read the message body of a mail. i am using pop3 server for reading the mails. my program is public class GetMessageExample { public static void main (String args[]) throws Exception { String host = args[0]; String username = args[1]; String password = args[2]; Properties props = new Properties(); Session session = Session.getInstance(props, null); Store store = session.getStore("pop3"); store.connect(host, username, password); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); BufferedReader reader = new BufferedReader ( new InputStreamReader(System.in));    More>>

how can we read the message body of a mail. i am using pop3 server for reading the mails. my program is

			
public class GetMessageExample {
public static void main (String args[]) throws Exception {
String host = args[0];
String username = args[1];
String password = args[2];

Properties props = new Properties();

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

Store store = session.getStore("pop3");
store.connect(host, username, password);

Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);

BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));

Message message[] = folder.getMessages();
for (int i=0, n=message.length; i
System.out.println(i + ": " + message[i].getFrom()[0]
+ " " + message[i].getSubject());

System.out.println(
"Do you want to read message? [YES to read/QUIT to end]");
String line = reader.readLine();
if ("YES".equals(line)) {
message[i].writeTo(System.out);
} else if ("QUIT".equals(line)) {
break;
}
}

folder.close(false);
store.close();
}
}




i am getting the following exception

			
Exception in thread "main" java.lang.NoSuchFieldError: contentStream
at com.sun.mail.pop3.POP3Message.getContentStream(POP3Message.java:115)
at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSou
rce.java:61)
at com.sun.mail.handlers.text_plain.getContent(text_plain.java:65)
at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.
java:755)
at javax.activation.DataHandler.getContent(DataHandler.java:511)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1072)
   <<Less

Re: How to read the message body in a mail

Posted By:   John_Zukowski  
Posted On:   Wednesday, October 17, 2001 11:33 PM

You seem to be mixing your JavaMail classes. Be sure you don't have two versions of JavaMail in your classpath.
About | Sitemap | Contact