  | 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
|
|
|
  | | | Java Mail Problem | Java Mail Problem 2003-11-19 - By Manoj Mallawaarachchie
Back 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) 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".
|
|
 |