dcsimg
Receiving Mails...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   hari_krishna
Posted On:   Wednesday, May 30, 2001 02:08 AM

On executing the program(Receiving Mails) **************************************** import javax.mail.*; import javax.mail.internet.*; import javax.mail.event.*; public class InBox { String protocol; String host; String user; String password; String mbox; Message[] msgs; Folder folder; Store store; InBox(String user, String pass, String popServer){ protocol = "pop3"; this.user = user; password = pass; host = popServer; mbox = "INBOX"; } public void openFolder()throws NoSuchProviderException, MessagingException{ java.util.Properties props = System.getPropertie   More>>

On executing the program(Receiving Mails)

****************************************
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.event.*;

public class InBox {
String protocol;
String host;
String user;
String password;
String mbox;
Message[] msgs;
Folder folder;
Store store;

InBox(String user, String pass, String popServer){
protocol = "pop3";
this.user = user;
password = pass;
host = popServer;
mbox = "INBOX";
}
public void openFolder()throws NoSuchProviderException, MessagingException{
java.util.Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);
store = session.getStore(protocol);
store.connect(host,user,password);

folder = store.getDefaultFolder();
if (folder == null) {
System.out.println("No default folder");
System.exit(1);
}
folder = folder.getFolder(mbox);
if (folder == null)
System.out.println("********Folder is null***********");
folder.open(Folder.READ_WRITE);
msgs = folder.getMessages();
}

public void getInbox()throws AuthenticationFailedException, MessagingException{
try{

Address[] add;
String sub;
String from;
for(int j = 0; j < msgs.length; j++)
{
if(( add = msgs[j].getFrom()) != null)
for(int k = 0; k < add.length; k++){
from = add[k].toString();
if(from == null)
System.out.println("From Address Unknown");
else
System.out.println("From Address " + from);;
}

sub = msgs[j].getSubject();
if(sub == null)
System.out.println("Subject Unknown");
else
System.out.println("Subject " + sub);
System.out.println("**************************** " + j+ " ****************************");
String message = getMessage(j);
System.out.println("Message


" + message);
}
}
catch(AuthenticationFailedException afe){
throw new AuthenticationFailedException();}
catch(MessagingException me){
throw new MessagingException();}
catch(Exception e){ }
folder.close(true);
store.close();

}
public String getMessage(int i) throws MessagingException{
Object obj = null;
String msg = "";
try{
msg = msg + getBodyPart(msgs[i]);
}catch(java.io.IOException e){
}catch(MessagingException me){
throw new MessagingException();
}
return msg;
}

public String getBodyPart(Part p) throws java.io.IOException, MessagingException {
Object obj = p.getContent();
String str = "";
if(obj instanceof String){
str = str + (String)obj;
}
else if(obj instanceof Multipart){
Multipart mp = (Multipart)obj;
int count = mp.getCount();
for(int i =0; i < count; i++){
str = str + getBodyPart(mp.getBodyPart(i));
}
}
else if (obj instanceof java.io.InputStream) {
/* InputStream is = (InputStream)obj;
int c;
while((c = is.read()) != -1)
System.out.write(c);*/
}
return str;
}

public static void main(String args[]){

InBox inbox = new InBox("uday", "uday", "202.56.199.2");
try{
inbox.openFolder();
inbox.getInbox();
}catch(NoSuchProviderException nospe){
System.out.println("NoSuchProviderException
");
nospe.printStackTrace();
}catch(AuthenticationFailedException mesg){
System.out.println("AuthenticationFailedException
");
mesg.printStackTrace();
}catch(MessagingException afe){
System.out.println("MessagingException
");
afe.printStackTrace();
}
}
}
****************************************
Iam getting the following error:

java.lang.NoSuchFieldError: javax.mail.internet.MimeMessage: field contentStream not found
****************************************
Please help me out in overcoming this error...

   <<Less

Re: Receiving Mails...

Posted By:   John_Zukowski  
Posted On:   Wednesday, May 30, 2001 09:18 PM

Make sure you have the latest JavaMail classes installed, not a mix of 1.1 and 1.2.
About | Sitemap | Contact