android - 使用android发送电子邮件而不发送电子邮件
问题描述
我正在尝试向使用 Android 的用户发送一封包含代码的电子邮件。无论出于何种原因,它都不起作用。
我已经按照这个教程
问题是什么?
这是代码:
public class PWReset extends AppCompatActivity {
EditText getMail;
Button Continue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pwreset);
getMail=findViewById(R.id.Mail);
Continue=findViewById(R.id.PWR2);
Continue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String Code = UUID.randomUUID().toString().substring(0, 5);
//After checking if the email is registered in the DB
resetPassword(getMail.getText().toString(), Code);
Intent intent = new Intent(PWReset.this, PWReset2.class);
intent.putExtra("code", Code);
startActivity(intent);
}
});
}
public void resetPassword(String Mail, String code){
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{getMail.getText().toString()});
email.putExtra(Intent.EXTRA_SUBJECT, "Password reset");
email.putExtra(Intent.EXTRA_TEXT, "You have requested a password reset.\nHere is the code for resetting your password:" + code +
"\nIf you have not requested a password reset, ignore this message.");
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "gmail"));
}
}