Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Interest »

Re: Java Mail Problem

Mooss, Vasudevan

2003-11-19

Replies:

Hi Manoj,

I am able to compile this code without any problem. You may still have
some issue with the CLASSPATH settings.

Regards,
Vasudevan Mooss





-----Original Message-----
From: A mailing list for Java(tm) 2 Platform, Enterprise Edition
[mailto:J2EE-INTEREST@(protected)
Sent: Thursday, 20 November, 2003 8:23 AM
To: J2EE-INTEREST@(protected)
Subject: Java Mail Problem

Hi All,

I'm try to read mail with attachment in mail server with using POP3 and
JavaMail Api when I going to compile it It's say following error

F:\>javac TestMail.java
TestMail.java:18: cannot resolve symbol
symbol : method getInstance (java.util.Properties,<null>)
location: class Session
Session session = Session.getInstance(props, null);
                ^
TestMail.java:21: cannot resolve symbol
symbol : method getStore (java.lang.String)
location: class Session
Store store = session.getStore("pop3");
             ^
TestMail.java:35: cannot resolve symbol
symbol : method getFrom ()
location: class javax.mail.Message[]
Address[] from = msg.getFrom();
            ^
TestMail.java:36: cannot resolve symbol
symbol : method getSubject ()
location: class javax.mail.Message[]
String subject = msg.getSubject();
            ^
TestMail.java:38: cannot resolve symbol
symbol : method getContent ()
location: class javax.mail.Message[]
Object o = msg.getContent();
        ^



My Java Codde is listed below and I add all the
imap.jar,pop3.jar,mail.jar, mailapi.jar to my CLASSPATH

############# Java CODE###########################

import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import javax.mail.Session.*;
import javax.mail.Message.*;


public class TestMail {

public static void main (String args[]) throws Exception {

// Create empty properties
Properties props = new Properties();

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

// Get the store
Store store = session.getStore("pop3");

// Connect to store
store.connect("myMailhostIP","manoj","mypassword"); //my account info

// Get folder
Folder topFolder = store.getDefaultFolder(); Folder folder =
topFolder.getFolder("INBOX"); folder.open(Folder.READ_WRITE);

Message[] msg = folder.getMessages();

for(int i = 0; i < msg.length; i++){

Address[] from = msg.getFrom();
String subject = msg.getSubject();

Object o = msg.getContent();

if (o instanceof MimeMultipart) { //attachements available?
MimeMultipart mm = (MimeMultipart) o;
int mmCount = mm.getCount();
for (int m = 0; m < mmCount; m++) { // for each part Part part =
mm.getBodyPart(m); String disposition = part.getDisposition();

if ((disposition != null) && ((disposition.equals(Part.ATTACHMENT) ||
disposition.equals(Part.INLINE)))) {
InputStream is = null;
File tempFile = new File("D:\\TEMP\\mailtest\\" + part.getFileName());
FileOutputStream fos = null; try { fos = new FileOutputStream(tempFile);
is = part.getInputStream(); int byteCount = 0; byte[] bytes = new
byte[128]; while ( (byteCount = is.read(bytes, 0, bytes.length)) > -1) {
//use full
read() method for GZIPInputStream to be treated correctly
fos.write(bytes, 0, byteCount); } } finally { try { if (fos != null)
fos.close(); } catch (IOException ioe) {} try { if (is != null)
is.close(); } catch (IOException ioe) {} } } } }

System.out.println("Content: " + o);
System.out.println(from[0].toString());
System.out.println(subject);
}
}
}



################ END OF JAVA CODE ####################





Please help me to trace the problem

Thank You
best regards
Manoj

========================================================================
===
To unsubscribe, send email to listserv@(protected)
body of the message "signoff J2EE-INTEREST". For general help, send
email to listserv@(protected)
"help".

===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".


©2008 junlu.com - Jax Systems, LLC, U.S.A.