Android: Using Intent To Send Email - Only Offering Email Applications Doesnt Work
i am trying to create an intent activity that sends an email. Using public void emailSend(View view){ Intent emailIntent = new Intent(Intent.ACTION_SEND); emailInte
Solution 1:
When I use intent android.content.Intent.ACTION_SENDTO doesn't work for me because it shows many apps, some apps are not email clients. I found this way and it works perfectly for me.
IntenttestIntent=newIntent(Intent.ACTION_VIEW);
Uridata= Uri.parse("mailto:?subject=" + "text subject" + "&body=" + "text content" + "&to=" + "email@example.com");
testIntent.setData(data);
startActivity(testIntent);
Solution 2:
This is code that I have working:
IntentintentMail=newIntent(Intent.ACTION_SEND);
intentMail.setType("message/rfc822");
intentMail.putExtra(Intent.EXTRA_EMAIL, newString[]{
"mailto@email.com" }); // the To mail.
intentMail.putExtra(Intent.EXTRA_SUBJECT, "Subject goes here");
intentMail.putExtra(Intent.EXTRA_TEXT, "Content goes here");
// now we have created the mail, lets try and send it.try {
startActivity(Intent.createChooser(intentMail, "Message to User to do what next"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Activity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
If this does not work, let me know. Oh, do you have the error logs?
*edit, this is where I found my code, so doublicate. Source
Solution 3:
I see only email clients when using the next approach:
IntentemailIntent=newIntent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_EMAIL, newString [] {someaddress@gmail.com});
emailIntent.putExtra(Intent.EXTRA_SUBJECT,"Email subject"));
Intentchooser= Intent.createChooser(emailIntent, "Mail to ..");
if (emailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
else//Do something if there's no Email client
Solution 4:
Finally after trying a variation of all these posts, I came up with this which works nicely:
funsendEmail(context: Context, email: String, subject: String = "") {
try {
context.startActivity(
Intent(Intent.ACTION_SENDTO).apply {
data = (Uri.parse("mailto:$email"))
.buildUpon()
.appendQueryParameter(
"subject", subject
).appendQueryParameter(
"to", email
)
.build()
}
)
} catch (e: Exception) {
Timber.e("failed to open mail client")
}
}
Solution 5:
This would do the job!
Intentintent=newIntent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, newString[] { "some@email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Post a Comment for "Android: Using Intent To Send Email - Only Offering Email Applications Doesnt Work"