How to send emails from my Android application?
The best (and easiest) way is to use an Intent
:
Intent i = new Intent(Intent.ACTION_SEND);i.setType("message/rfc822");i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});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, "There are no email clients installed.", Toast.LENGTH_SHORT).show();}
Otherwise you'll have to write your own client.
I've been using this since long time ago and it seems good, no non-email apps showing up. Just another way to send a send email intent:
Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SENDintent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");intent.putExtra(Intent.EXTRA_TEXT, "Body of email");intent.setData(Uri.parse("mailto:default@recipient.com")); // or just "mailto:" for blankintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.startActivity(intent);