2017-09-22 22 views
0

ofice365アカウントからメールを送信中にJavaエラーが発生しました。ofice365アカウントからメールを送信中にJavaでエラーが発生しました

javax.mail.AuthenticationFailedException:535 5.7.3認証の失敗[MA1PR01CA0090.INDPRD01.PROD.OUTLOOK.COM]

はここに私のコードです。電子メールとパスワードは正しいです。私を助けてください。

final String username = StaticParameters.adminEmail; 
    final String password = StaticParameters.adminPassword; 

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

    Session session = Session.getInstance(props, 
     new javax.mail.Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(username, password); 
     } 
     }); 

    try { 
     Message message = new MimeMessage(session); 
     message.setFrom(new InternetAddress(username)); 
     message.setRecipients(Message.RecipientType.TO, 
      InternetAddress.parse(to)); 
     message.setSubject(subject); 
     message.setContent(body, "text/html; charset=utf-8"); 
     Transport.send(message); 
     System.out.println("Done"); 
     return true; 

    } catch (MessagingException e) { 

     throw new RuntimeException(e); 
    } 
+0

uは、いくつかの電子メールクライアントを経由して、同じ情報を使用してサーバを接続することができますか? – Optional

+0

私はどの電子メールクライアントをテストに使用できますか? –

+0

いずれか1つ、たとえばサンダーバードの見通し – Optional

答えて

0

これを試してみてください:

private static Properties props; 
    private static Session session; 
    static { 
     props = new Properties(); 
     props.put("mail.smtp.starttls.enable", "true"); 
     props.put("mail.smtp.port", "587"); 
     props.put("mail.smtp.host", "m.outlook.com"); 
     props.put("mail.smtp.auth", "true"); 
     session = Session.getInstance(props, new Authenticator() { 
      @Override 
      protected PasswordAuthentication getPasswordAuthentication() { 
       return new PasswordAuthentication("office365 email address" 
         "office365 password"); 
      } 
     }); 

    } 
+0

同じエラーが発生しています。ありがとう –

関連する問題