无法发送密码提醒电子邮件

时间:2015-08-30 14:04:23

标签: android password-recovery

我尝试创建某种密码提醒,将密码发送给用户电子邮件。 相反,每当我尝试通过应用程序发送此邮件时,我只能访问发送短信页面。 我使用的是最新的android studio版本。

    public void ForgetPasswordEvent (View view) {
        //AlertDialog recovery = new AlertDialog();
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Please enter your registered email");
// Set up the input
        final EditText input = new EditText(this);
// Specify the type of input expected;
        input.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
        builder.setView(input);
// Set up the buttons
        builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                m_Text= input.getText().toString();
                Log.i("Send email", "");

//              String[] TO = {m_Text.toString()};
                String[] TO = {"erez@manageyourtrip.com"};
                String[] CC = {"erez@manageyourtrip.com"};
                Intent emailIntent = new Intent(Intent.ACTION_SEND);
                emailIntent.setData(Uri.parse("mailto:"));
                emailIntent.setType("text/plain");


                emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
                emailIntent.putExtra(Intent.EXTRA_CC, CC);
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, "MYT GuideApp password recovery");
                emailIntent.putExtra(Intent.EXTRA_TEXT, "Your password is 123456");

                try {
                    startActivity(createChooser(emailIntent, "Send mail..."));
                    finish();
                    Log.i("Finished sending email", "");
                } catch (android.content.ActivityNotFoundException ex) {
                    Toast.makeText(MainActivity.this,
                            "There is no email client installed.", Toast.LENGTH_SHORT).show();
                }

            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        builder.show();

1 个答案:

答案 0 :(得分:0)

setType("text/plain")太“宽”了。

你应该使用类似的东西:

setType("message/rfc822")

免责声明:我仍然不赞成这种功能。我不会使用(或推荐)能够发送我密码的应用程序。

来源:Another question asking the same thing