Reputation: 1099
Hi I have got this edit text field, when I click on this button I want what ever is on the edit text box to be emailed to a specific email address. How do I go about doing that ?
findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "[email protected]", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "");
intent.putExtra(Intent.EXTRA_TEXT, R.id.feedback_comment);
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
as you can see my edit text id is "feedback_comment". And I am passing that in the message.
I would also like to know if there is any way I could send this email in the background so that user doesn't have to see all of this in the front end. You click on the submit button and it sends the email to the specified address without having to play around on sending an email. I had a look at JavaMail and don't know where to start off, please someone help me start off. Thank You
Upvotes: 0
Views: 2213
Reputation: 6871
You can use javaMail which has been ported to Android.
See more at :
Hope it can help you.
Upvotes: 0
Reputation: 1261
first in onCreate ..
EditText editText = findViewById(R.id. feedback_comment);
then..
findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");
intent.putExtra(Intent.EXTRA_SUBJECT, "SUBJECT");
intent.putExtra(Intent.EXTRA_TEXT, editText.getText().toString().trim());
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
});
Upvotes: 1