Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Read Mail From A Folder

Threaded View

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Read Mail From A Folder

    Hello to all in this forum. I'm new in Java and try to learn through the programs that I create.
    So I try to create a programm tha reads e-mails from a local folder. My problem is that I can't open that folder.
    I don't know what I'm doing wrong. Βelow is the code of my programm.

    import java.io.*;
    import java.util.*;
    import javax.mail.*;
     
    public class MailREad {  
     
    	public static void main(String args[]) throws Exception {  
     
    		String path = "C:\\Users\\Desktop\\mail folder";
    			Folder folder =null;
     
    		folder.open(path); //this is the problem
     
    		Message[] message = folder.getMessages(); 
     
    		//mail
     
            for (int i = 0; i < message.length; i++) {
     
                System.out.println("------------ Message " + (i + 1) + " ------------");
     
                System.out.println("SentDate : " + message[i].getSentDate());
                System.out.println("From : " + message[i].getFrom()[0]);
                System.out.println("Subject : " + message[i].getSubject());
                System.out.print("Message : ");
     
                InputStream stream = message[i].getInputStream();
                while (stream.available() != 0) {
                    System.out.print((char) stream.read());
                }
                System.out.println();
            }
    	}

    Thank you in advance for your answers.
    Last edited by JavaPF; January 27th, 2011 at 08:37 AM. Reason: Please use [highlight=Java] code [/highlight] tags..


Similar Threads

  1. How to Send emails from Google Mail using JavaMail API
    By JavaPF in forum Java SE API Tutorials
    Replies: 3
    Last Post: February 26th, 2012, 04:21 PM
  2. java mail
    By erinbasim in forum Java SE APIs
    Replies: 2
    Last Post: May 13th, 2010, 02:17 AM
  3. Getting information from a folder
    By shadihrr in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: February 23rd, 2010, 04:13 PM
  4. Javax.Mail Query Help Me Please
    By ravjot28 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 19th, 2010, 11:06 AM
  5. Sending and Receiving mail using J2ME without server
    By chals in forum Java ME (Mobile Edition)
    Replies: 5
    Last Post: June 2nd, 2009, 09:59 AM