2017-02-07 7 views
-1

ボタンを押すと自動メールを送信するためにJavaメールを使用しています。 アンドロイドスタジオで働いていますが、エラーjavax.mail.AuthenticationFailedExceptionが表示され、その理由が見つかりません。Javaメールが正しく動作しない

  • 私は25にポートを変更してみました - 587と465
  • Idは
  • Gmailアカウントが低く、安全なアプリケーションに開いているエミュレータ上で、実際のデバイス上で試してみました正しい

コードは次のとおりです。

Properties props = new Properties(); 
     props.put("mail.smtp.host" , "smtp.gmail.com"); 
     props.put("mail.stmp.user" , "[email protected]"); 

     //TLS 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.starttls.enable", "true"); 
     props.put("mail.smtp.password", "xxxxx"); 

     //SSL 
     props.put("mail.smtp.socketFactory.port", "465"); 
     props.put("mail.smtp.socketFactory.class", 
       "javax.net.ssl.SSLSocketFactory"); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.port", "465"); 

     Session session = Session.getDefaultInstance(props , null); 
     String to = "[email protected]"; 
     String from = "[email protected]"; 
     String subject = "Testing..."; 
     Message msg = new MimeMessage(session); 
     try { 
      msg.setFrom(new InternetAddress(from)); 
      msg.setRecipient(Message.RecipientType.TO, 
        new InternetAddress(to)); 
      msg.setSubject(subject); 
      msg.setText("Working fine..!"); 
      Transport transport = session.getTransport("smtp"); 
      transport.connect("smtp.gmail.com" , 465 , "[email protected]", "xxxx"); 
      transport.send(msg); 
      System.out.println("fine!!"); 
     } 
     catch(Exception exc) { 
      System.out.println(exc); 
     } 
+1

新しいコードを使用して記事を更新、(http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes)これらの[共通のJavaMailミス]を修正し、それでも動作しない場合は、[JavaMailデバッグ出力](http://www.oracle.com/technetwork/java/javamail/faq/index.html#debug)でポストを更新してください。 –

答えて

関連する問題