Javamail 传输成功使用无效凭据进行身份验证

Javamail transport getting success to authenticate with invalid credentials

我有这个验证电子邮件和密码的代码。如果我使用有效的凭据,只要我 运行 应用程序,它就会进行身份验证。但是,如果我注销并尝试使用一些无效凭据再次登录,它会继续成功进行身份验证并且不会出现异常。似乎 Transport 正在缓存以前的数据(有效凭据)并在我再次登录时使用它。我查了,变量"email"和"password"没有问题。当我先尝试一些无效的凭据然后再尝试一些有效的凭据时,就会发生相反的情况。你们知道发生了什么事吗?

这是它发生的代码片段:

谢谢!

public void check_user(final String email, final String password){
    final ProgressDialog pb = new ProgressDialog(this);
    pb.setIndeterminate(true);
    pb.setTitle("Verificando usuário");
    pb.setMessage("Por favor, aguarde...");
    pb.setCancelable(false);
    pb.show();
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            Properties props = new Properties();

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

            Session session = Session.getDefaultInstance(props,
                    new javax.mail.Authenticator() {
                        //Authenticating the password
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(email, password);
                        }
                    });

            try {
                transport = session.getTransport("smtp");
                transport.connect(email, password);
                transport.close();
             } catch (Exception e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(LoginActivity.this, "Usuário e/ou senha inválidos.", Toast.LENGTH_LONG).show();
                        pb.dismiss();
                    }
                });
                return;
            }
            SharedPreferences.Editor data = getSharedPreferences("user_data", 0).edit();


            data.putString("username", email).commit();
            data.putString("password", password).commit();
            data.putBoolean("isLogged", true).commit();
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    get_in();
                }
            });

        }
    });
    t.start();

}

Change Session.getDefaultInstance to Session.getInstance.