-3

Lets say I have a button and an edit text in a layout. How do i send an email that says some messages to that address which is the edit text in android studio ?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

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")));
Yogesh Telang
  • 74
  • 1
  • 6
0

First Get text from your email edittext. Then use this email to whom you are sending email.

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();
}
Nabeel Nazir
  • 420
  • 5
  • 15
  • createChooser creates a client chooser dialog box right? is there any way to specify email address directly that is to be sent from without creating the choose dialog box? – TesseractT.Shailab Mar 02 '18 at 09:48
  • This might help you. http://www.edumobile.org/android/send-email-on-button-click-without-email-chooser/ – Nabeel Nazir Mar 02 '18 at 09:57