Reputation: 39
I get no error but the mail-to will not be showed ! it stays empty
public void Send_Mail(View view) {
String txt_context = "My comment about the App : \n The App is good but does not support v3";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setData(Uri.parse("mailto:"));
intent.setType("message/rfc822"); //
intent.putExtra(Intent.EXTRA_EMAIL,"[email protected]"); // **this will not displayed** """
intent.putExtra(Intent.EXTRA_SUBJECT,"Comment about the APP");
intent.putExtra(Intent.EXTRA_TEXT,txt_context);
startActivity(intent);
Upvotes: 3
Views: 2990
Reputation: 101
For kotlin The emial must be an arrayOf, nos just a string.
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
Upvotes: 2
Reputation: 125
The disadvantage of doing it your way is that it gives gmail issues retrieving the address to send the mail to, and so many apps support message/rfc822
so your user can get drowned in different clients. I advice you use
Intent sendMail = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("[email protected]") +
"?subject=" + Uri.encode("subject") +
"&body=" + Uri.encode("body);
Uri uri = Uri.parse(uriText);
sendMail.setData(uri);
startActivity(Intent.createChooser(sendMail, "Choose a client"));
as this is a bit more specific than specifying with intent.setType("message/rfc822");
and solves the issue with gmail. Good Luck.
Upvotes: 4
Reputation: 3869
I know this post is old but I encountered the same issue and I found the solution (in the official documentation):
As explained, Intent.EXTRA_EMAIL
is:
A String[] holding e-mail addresses that should be delivered to.
So to fix your issue, instead of:
intent.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
do:
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
Upvotes: 6
Reputation: 185
This is how you correctly send an email via an intent. The URI arguments are required if not you will have problems getting Gmail to receive your emails.
Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("[email protected]") +
"?subject=" + Uri.encode("the subject") +
"&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);
send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));
Upvotes: 4