如何将电子邮件发送到存储在EditText中的地址?

时间:2018-03-02 09:24:55

标签: android email send

假设我在布局中有一个按钮和一个编辑文本。如何发送一封电子邮件,说明某些消息到该地址,这是android studio中的编辑文本?

2 个答案:

答案 0 :(得分:2)

 String email = editText.getText().toString();
 Intent intent = new Intent(Intent.ACTION_SENDTO, 
 Uri.parse("mailto:" + email));
 intent.putExtra(Intent.EXTRA_SUBJECT, "Enter subject here");
 intent.putExtra(Intent.EXTRA_TEXT, "Enter email body here");
 startActivity(Intent.createChooser(intent, 
 "Choose email client")));

答案 1 :(得分:0)

首先从您的电子邮件edittext获取文字。然后使用此电子邮件向您发送电子邮件。

String email = emailfield.getText().toString()
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , email);
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
   startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "No email clients installed.",   Toast.LENGTH_SHORT).show();
}