users@glassfish.java.net

plzz help i cant download mine emails with the help of this code

From: <glassfish_at_javadesktop.org>
Date: Sat, 19 Jul 2008 22:06:35 PDT

[code]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/* aurthor dic members
* devolopment version 0.1
*website= www.dreamincode.net
*/

import com.sun.mail.pop3.POP3SSLStore;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.URLName;
import javax.mail.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Properties;

public class Javamail extends JFrame {

    Session session;
    Aok okss;
    Store store;
    JLabel password, username, localdir, folders, attachments, dname, lport;
    JButton bok, bexit;
    JTextField tpassword, tusername, tlocaldir, tfolders, tattachments, tdname, tport;
    Aexit acexit;
    String spassword, susername, slocaldir, sfolders, sattachments, sdname;
    String serverfolder = "INBOX";
    Folder folder;
    Properties pop3Props;
    URLName url;

    Javamail() {
        setTitle("java mail");
        password = new JLabel("password");
        username = new JLabel("username");
        localdir = new JLabel("localdir");
        folders = new JLabel("folder");
        attachments = new JLabel("Attachments");
        tpassword = new JTextField();
        tusername = new JTextField();
        tlocaldir = new JTextField();
        tfolders = new JTextField();
        tattachments = new JTextField();
        bok = new JButton("ok");
        bexit = new JButton("exits");
        dname = new JLabel("domain-name");
        tdname = new JTextField("tdname");
        lport = new JLabel("Server Port");
        tport = new JTextField();
        Container pane = getContentPane();
        pane.setLayout(new GridLayout(8, 8));
        //add compnets container


        pane.add(dname);
        pane.add(tdname);
        pane.add(username);
        pane.add(tusername);
        pane.add(password);
        pane.add(tpassword);
        pane.add(localdir);
        pane.add(tlocaldir);
        pane.add(folders);
        pane.add(tfolders);
        pane.add(attachments);
        pane.add(tattachments);
        pane.add(lport);
        pane.add(tport);

        pane.add(bok);

        acexit = new Aexit();
        okss = new Aok();
        pane.add(bexit);
        bexit.addActionListener(acexit);
        bok.addActionListener(okss);
        setVisible(true);


    }
    //action listners for exit button
    class Aexit implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            //exit with ok status
            System.out.println("exited");
            System.exit(0);

        }
    }
    //including actionlistener
    class Aok implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            spassword = tpassword.getText();
            susername = tusername.getText();
            slocaldir = tlocaldir.getText();
            sfolders = tfolders.getText();
            sdname = tdname.getText();
            sattachments = tattachments.getText();


            initialize();
            System.out.println("initialization of properties is complete");

            mailreader();

        }
    }
    //copying message to a folder
    public void initialize() {

        String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

        pop3Props = new Properties();

        pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
        pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
        pop3Props.setProperty("mail.pop3.port", "995");
        pop3Props.setProperty("mail.pop3.socketFactory.port", "995");



        url = new URLName("pop3", "pop.gmail.com", 995, "",
                susername, spassword);


    }

    void mailreader() {
        System.out.println("authenthicating");
        session = Session.getInstance(pop3Props, null);
        store = new POP3SSLStore(session, url);
        System.out.println("authenctication complete got instance");



        //get session for the code from the server

        

        try {

            
            store.connect();

            System.out.println("authentication with user , password and dname complete");
        } catch (MessagingException ex) {
            ex.printStackTrace();
        }

        try {
            if (store.isConnected()) {

                folder = store.getFolder("INBOX");
                folder.open(Folder.READ_WRITE);
                System.out.println("opened inbox folder");



                System.out.println("total nuber of messages" + folder.getMessageCount());
                Message[] msg = folder.getMessages();

                int len = msg.length;


                for (int i = 0; len < len; i++) {

                    System.out.println("subject: " + msg[i].getSubject());

                }

            }

        } catch (MessagingException ex) {
            ex.printStackTrace();
        }




    }

    public static void main(String args[]) {
        Javamail m = new Javamail();
    }
}
    
[/code]
and nor this work
[code]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/* aurthor prajay shetty & dic members
* devolopment version 0.1
*website= www.dreamincode.net
*/
package javamailstore;

import javax.mail.*;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.util.Properties;

public class Main extends JFrame {

    Aok okss;
    Store store;
    JLabel password, username, localdir, folders, attachments, dname, lport;
    JButton bok, bexit;
    JTextField tpassword, tusername, tlocaldir, tfolders, tattachments, tdname, tport;
    Aexit acexit;
    String spassword, susername, slocaldir, sfolders, sattachments, sdname, sport;
    String serverfolder = "INBOX";
    Folder dfolder;
    Properties props;
    AccountAuthentication auth;

    Main() {
        setTitle("java mail");
        password = new JLabel("password");
        username = new JLabel("username");
        localdir = new JLabel("localdir");
        folders = new JLabel("folder");
        attachments = new JLabel("Attachments");
        tpassword = new JTextField();
        tusername = new JTextField();
        tlocaldir = new JTextField();
        tfolders = new JTextField();
        tattachments = new JTextField();
        bok = new JButton("ok");
        bexit = new JButton("exits");
        dname = new JLabel("domain-name");
        tdname = new JTextField("tdname");
        lport = new JLabel("Server Port");
        tport = new JTextField();
        Container pane = getContentPane();
        pane.setLayout(new GridLayout(8, 8));
        //add compnets container

        pane.add(dname);
        pane.add(tdname);
        pane.add(username);
        pane.add(tusername);
        pane.add(password);
        pane.add(tpassword);
        pane.add(localdir);
        pane.add(tlocaldir);
        pane.add(folders);
        pane.add(tfolders);
        pane.add(attachments);
        pane.add(tattachments);
        pane.add(lport);
        pane.add(tport);

        pane.add(bok);

        acexit = new Aexit();
        okss = new Aok();
        pane.add(bexit);
        bexit.addActionListener(acexit);
        bok.addActionListener(okss);
        setVisible(true);


    }
    //action listners for exit button
    class Aexit implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            //exit with ok status
            System.out.println("exited");
            System.exit(0);

        }
    }
    //including actionlistener
    class Aok implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            spassword = tpassword.getText();
            susername = tusername.getText();
            slocaldir = tlocaldir.getText();
            sfolders = tfolders.getText();
            sdname = tdname.getText();
            sattachments = tattachments.getText();
            sport = tport.getText();

            initialize();
            System.out.println("initialization of properties is complete");

            mailreader();

        }
    }

    public class AccountAuthentication extends javax.mail.Authenticator {

        @Override
        public PasswordAuthentication getPasswordAuthentication() {

            return new PasswordAuthentication(susername, spassword);
        }
    }

    public void initialize() //copying message to a folder
    {
        //initializing properties
        props = new Properties();
        props.put("mail.pop3.host", dname);
        props.put("mail.pop3.user", susername);
        props.put("mail.pop3.port", sport);
        props.put("mail.pop3.starttls.enable", "true");
        props.put("mail.pop3.auth", "true");
        props.put("mail.pop3.socketFactory.port", sport);
        props.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.pop3.socketFactory.fallback", "false");


    }

    void mailreader() {
        System.out.println("authenthicating");
        auth = new AccountAuthentication();
        Session session = Session.getDefaultInstance(props, auth);
        System.out.println("authenctication complete got instance");

        try {

            //get session for the code from the server

            store = session.getStore("pop3");
            System.out.println("connecting to store");
            try {

                store.connect(sdname, susername, spassword);
                System.out.println("authentication with user , password and dname complete");
            } catch (MessagingException ex) {
                ex.printStackTrace();
            }

            try {
                if (store.isConnected()) {

                    Folder inboxFolder = store.getFolder("INBOX");
                    inboxFolder.open(Folder.READ_WRITE);
                    System.out.println("opened inbox folder");
                    System.out.println("Message Count:" + inboxFolder.getMessageCount());

                    Message[] msg = inboxFolder.getMessages();

                    int len = msg.length;


                    for (int i = 0; len < len; i++) {

                        System.out.println("subject: " + msg[i].getSubject());

                    }

                }

            } catch (MessagingException ex) {
                ex.printStackTrace();
            }


        } catch (NoSuchProviderException ex) {
            ex.printStackTrace();
        }

    }

    public static void main(String args[]) {
        Main m = new Main();
    }
}
[/code] plzz help me
[Message sent by forum member 'herorocks' (herorocks)]

http://forums.java.net/jive/thread.jspa?messageID=287882