Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Java Mail Problem

Java Mail Problem

2003-11-19       - By Manoj Mallawaarachchie

 Back
Reply:     1     2     3     4  

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 Source code of 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 Source code of 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 Source code of javax.mail.Session
import javax.mail.Message Source code of 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) and include in the body
of the message "signoff J2EE-INTEREST".  For general help, send email to
listserv@(protected) and include in the body of the message "help".



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