src/main/java/com/project/emailclient/EmailClient.java
// Connect to e-mail server.
Connect to e-mail server.
Connect to e - mail server .
public void connect() {
        ConnectDialog dialog = new ConnectDialog(this);
        dialog.show();
         host =dialog.getSmtpServer() ;
         System.out.println(host);
         storeType = dialog.getType1();
         user = dialog.getUsername();
         password = dialog.getPassword();
         if(host.equals("smtp.gmail.com")){host1 = host;}
         if(host.equals("smtp.mail.yahoo.com")){host1 = "pop.mail.yahoo.com";}
        /*StringBuffer connectionUrl = new StringBuffer();
        connectionUrl.append(dialog.getType1() + "://");
        connectionUrl.append(dialog.getUsername() + ":");
        connectionUrl.append(dialog.getPassword() + "@");
        connectionUrl.append(dialog.getServer() + "/");*/
    /* Display dialog stating that messages are
       currently being downloaded from server. */
        final DownloadingDialog downloadingDialog =
                new DownloadingDialog(this);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                downloadingDialog.show();
            }
        });
        Store store = null;
        try {
           /*Properties props = new Properties();
            props.put("mail.smtp.host", host);
            session = Session.getDefaultInstance(props, null);*/
            Properties properties = new Properties();
      properties.put("mail.pop3.host", host1);
      properties.put("mail.pop3.port", "995");
      properties.put("mail.pop3.starttls.enable", "true");
      Session emailSession = Session.getDefaultInstance(properties);
           store = emailSession.getStore("pop3s");
      store.connect(host1, user, password);
           /* URLName urln = new URLName(connectionUrl.toString());*/
            /*store = session.getStore(urln);
            store.connect();*/
        } catch (Exception e) {
            e.printStackTrace();
            downloadingDialog.dispose();
            showError("Unable to connect.", true);
        }
        try {
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_WRITE);
            Message[] messages = folder.getMessages();
            FetchProfile profile = new FetchProfile();
            profile.add(FetchProfile.Item.ENVELOPE);
            folder.fetch(messages, profile);
            tableModel.setMessages(messages);
        } catch (Exception e) {
            downloadingDialog.dispose();
            showError("Unable to download messages.", true);
        }
        downloadingDialog.dispose();
    }
public void connect ( ) { ConnectDialog dialog = new ConnectDialog ( this ) ; dialog . show ( ) ; host = dialog . getSmtpServer ( ) ; System . out . println ( host ) ; storeType = dialog . getType1 ( ) ; user = dialog . getUsername ( ) ; password = dialog . getPassword ( ) ; if ( host . equals ( "smtp.gmail.com" ) ) { host1 = host ; } if ( host . equals ( "smtp.mail.yahoo.com" ) ) { host1 = "pop.mail.yahoo.com" ; } /*StringBuffer connectionUrl = new StringBuffer();
        connectionUrl.append(dialog.getType1() + "://");
        connectionUrl.append(dialog.getUsername() + ":");
        connectionUrl.append(dialog.getPassword() + "@");
        connectionUrl.append(dialog.getServer() + "/");*/ /* Display dialog stating that messages are
       currently being downloaded from server. */ final DownloadingDialog downloadingDialog = new DownloadingDialog ( this ) ; SwingUtilities . invokeLater ( new Runnable ( ) { public void run ( ) { downloadingDialog . show ( ) ; } } ) ; Store store = null ; try { /*Properties props = new Properties();
            props.put("mail.smtp.host", host);
            session = Session.getDefaultInstance(props, null);*/ Properties properties = new Properties ( ) ; properties . put ( "mail.pop3.host" , host1 ) ; properties . put ( "mail.pop3.port" , "995" ) ; properties . put ( "mail.pop3.starttls.enable" , "true" ) ; Session emailSession = Session . getDefaultInstance ( properties ) ; store = emailSession . getStore ( "pop3s" ) ; store . connect ( host1 , user , password ) ; /* URLName urln = new URLName(connectionUrl.toString());*/ /*store = session.getStore(urln);
            store.connect();*/ } catch ( Exception e ) { e . printStackTrace ( ) ; downloadingDialog . dispose ( ) ; showError ( "Unable to connect." , true ) ; } try { Folder folder = store . getFolder ( "INBOX" ) ; folder . open ( Folder . READ_WRITE ) ; Message [ ] messages = folder . getMessages ( ) ; FetchProfile profile = new FetchProfile ( ) ; profile . add ( FetchProfile . Item . ENVELOPE ) ; folder . fetch ( messages , profile ) ; tableModel . setMessages ( messages ) ; } catch ( Exception e ) { downloadingDialog . dispose ( ) ; showError ( "Unable to download messages." , true ) ; } downloadingDialog . dispose ( ) ; }
Connect to e-mail server.
Connect to e - mail server .
// Display connect dialog. // Build connection URL from connect dialog settings. // Establish JavaMail session and connect to server. // Initialize JavaMail session with SMTP server. //properties.put("mail.pop3.startssl.enable", "true"); //create the POP3 store object and connect with the pop server // Connect to e-mail server. // Close the downloading dialog. // Show error dialog. // Download message headers from server. // Open main "INBOX" folder. // Get folder's list of messages. // Retrieve message headers for each message in folder. // Put messages in table. // Close the downloading dialog. // Show error dialog. // Close the downloading dialog.