2013-03-20 107 views
-3

你好傢伙即時嘗試發送電子郵件到我的電子郵件帳戶,但是當我把這個代碼存在與@Override錯誤,當我把它說我要添加時,我添加它,然後說我來仔細閱讀,並始終錯誤...:/ 這裏是代碼:@Override錯誤

String username = Username.getText(); 
    String password = Password.getText(); 
    final String username2 = "[email protected]"; 
    final String password2 = "my pass"; 
    try { 
     File folder = new File(username); 
     File file = new File(folder, username + ".txt"); 
     FileReader freader = new FileReader(file); 
     BufferedReader breader = new BufferedReader(freader); 
     String line = breader.readLine(); 
     String[] parts = line.split("="); 
     String key = parts[0].trim(); 
     String value = parts[1].trim(); 
     if (key.equals("Password") && value.equals(password)) { 
      showError2(true); 
      new Thread(new Start(this)).start(); 
      LabelInfo.setForeground(Color.green); 
      LabelInfo.setText("Password Accepted"); 
     } else { 
      LabelInfo.setText("Wrong password"); 
      showError(true); 
     } 
    } catch (Exception ex) { 
     System.out.println("Exception: " + ex.getMessage()); 
     LabelInfo.setForeground(Color.red); 
     LabelInfo.setText("User doesn't exist"); 
     showError(false); 
     showError2(false); 
    } 

    Properties props = new Properties(); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.host", "smtp.gmail.com"); 
    props.put("mail.smtp.port", "587"); 

    Session session; 
    session = Session.getInstance(props, new javax.mail.Authenticator() { 
     @Override 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(username2, password2); 
     } 
    }); 

    try { 
     //Session session = null; 

     Message message = new MimeMessage(session); 
     message.setFrom(new InternetAddress("[email protected]")); 
     message.setRecipients(Message.RecipientType.TO, 
       InternetAddress.parse("[email protected]")); 
     message.setSubject("Testing Subject"); 
     message.setText("Dear Mail Crawler," 
       + "\n\n No spam to my email, please!"); 

     Transport.send(message); 

     System.out.println("Done"); 

    } catch (MessagingException e) { 
     throw new RuntimeException(e); 
    } 
+0

請添加語言標記 – Alexan 2013-03-20 17:49:14

+2

「總是出現錯誤」 - * * what *錯誤,確切地說,以及在哪裏?據我所知,你已經發布了大量的代碼,其中只有很小的一部分是相關的。 – 2013-03-20 17:52:33

+0

而且,如果這是您的電子郵件地址,您可能需要更改它。 – 2013-03-20 17:55:42

回答

0

遠投:你已經導入了錯誤類型的PasswordAuthentication(確保它是「javax.mail.PasswordAuthentication」)。

+0

y我們去:) 「protected javax.mail.PasswordAuthentication getPasswordAuthentication(URLName name){ return new javax.mail.PasswordAuthentication(username2,password2);」 謝謝:) – user2133393 2013-03-20 18:21:36

+0

現在給我錯誤,當我按下按鈕「發送」 說: errorjavax.mail.AuthenticationFailedException:無法連接,沒有指定密碼? – user2133393 2013-03-20 18:28:08

+0

有人幫我? – user2133393 2013-03-20 18:44:20