I am developing an application in Android. I don't know how to send an email from the application?
-
Simple ShareBuilder https://gist.github.com/gelldur/9c199654c91b13478979 – Gelldur May 27 '15 at 10:43
-
Does this answer your question? [Android Studio mailto Intent doesn't show subject and mail body](https://stackoverflow.com/questions/59314608/android-studio-mailto-intent-doesnt-show-subject-and-mail-body) – Alex Aug 06 '20 at 12:57
-
The suggested duplicate seems worse, the accepted answer has a bizarre, unnecessary intent-filter. – Ryan M Aug 07 '20 at 05:49
26 Answers
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.
RFC822 is the standard for ARPA Internet Text Messages. See https://w3.org/Protocols/rfc822.

- 20,030
- 7
- 43
- 238

- 47,151
- 38
- 123
- 143
-
7In the above code,there is no sender email id.Then how the message send? – KIRAN K J Jun 23 '11 at 04:12
-
40KIRAN: You'll need to look into how Intents work to understand this. It'll basically open an email application with the recipient, subject, and body already filled out. It's up to the email app to do the sending. – Jeremy Logan Jul 11 '11 at 20:36
-
8The email is not appearing in "TO" field by starting the activity. anyone knows? – Hamza Waqas Mar 26 '12 at 12:03
-
1Its also showing bluetooth to complete the action.How this can be done only by mail? I don't need bluetooth option. – Dray Sep 11 '12 at 06:00
-
5Yeah... this worked perfect, until Skype also decided to "support" message/rfc822 - now Skype pops-up in list also. That company is truly becoming evil... – nikib3ro Oct 09 '12 at 20:56
-
2You can't "force" it to be an email app unless you know exactly which app the user would want to use. – Jeremy Logan Oct 19 '12 at 16:14
-
1Although forcing it to be a specific email app is not possible in general, you can limit the chooser to only display email apps. See [this alternative answer](http://stackoverflow.com/a/12804063/249239). Worked beautifully for me. – darrenp Sep 04 '13 at 18:46
-
I just have a question on this one of how to listen back if email sending fails do we have to use intent filters for that ? – Just Variable May 12 '14 at 06:00
-
One phone I tested this on suggested sending the email using "Bluetooth" and "Android Beam". The `ACTION_SENDTO` approach doesn't seem to have this problem. – Sam Jun 25 '15 at 12:59
-
28add these to be sure that chooser displays only email apps: `Intent i = new Intent(Intent.ACTION_SENDTO);` `i.setType("message/rfc822");` `i.setData(Uri.parse("mailto:"));` – Edris Oct 07 '15 at 13:41
-
3From the [official Android docs](http://developer.android.com/reference/android/content/Intent.html#ACTION_CHOOSER): "An example of when not to use it [`Intent.createChooser`] is when the user clicks on a "mailto:" link. They would naturally expect to go directly to their mail app, so startActivity() should be called directly: it will either launch the current preferred app, or put up a dialog allowing the user to pick an app to use and optionally marking that as preferred." – Ben Hutchison Mar 02 '16 at 05:20
-
-
1@Ozuf You can't unless the desire email app suports some kind of callbacks (via intents for example). AFAIK Gmail has no such tools. – Daniels Šatcs Jul 17 '16 at 14:23
-
@JeremyLogan using this but stil getting image in junk folder. how to get in inbox ? – Erum Nov 10 '16 at 09:23
-
Is it possible to also put sender email as extra? I cannot find it anywhere – K.Os May 11 '17 at 13:06
-
-
1
-
this is the best solution if you want to see only mail apps (not whatsapp etc) https://stackoverflow.com/questions/8701634/send-email-intent/16217921#16217921 – chezi shem tov Apr 26 '21 at 14:31
Use .setType("message/rfc822")
or the chooser will show you all of the (many) applications that support the send intent.
-
5Nice, this should have more up votes tbh. You won't notice testing on the emulator, but when you go to send "text/plain" on a real device it will give you a list of 15+ apps!! so "message/rfc822" is definitely recommended (the email standard). – Blundell Jul 23 '11 at 21:28
-
8@Blundell hi, but I didn't see any difference after changing to `message/rfc822` – draw Aug 13 '11 at 09:56
-
2Can you remove bluetooth from the list? This also shows up with this type. +1 though, neat trick! – ingh.am Aug 22 '11 at 15:52
-
6Saved our bacon. Can't imagine explaining to client that the user might tweet support requests instead of emailing them. – Kevin Galligan Jan 23 '12 at 23:03
-
-
1+1111111 This deserves endless +1's so others can see this. I missed this portion and had to deal with this problem for a while! – ChallengeAccepted Aug 06 '14 at 09:50
-
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_SEND
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
intent.putExtra(Intent.EXTRA_TEXT, "Body of email");
intent.setData(Uri.parse("mailto:default@example.com")); // or just "mailto:" for blank
intent.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);

- 23,933
- 14
- 88
- 109

- 71,383
- 57
- 178
- 228
-
2
-
I get an error: ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SENDTO typ=plain/text flg=0x10000000 } – IgorGanapolsky Aug 15 '12 at 13:33
-
4
-
2
-
1this code willl open email intent ? how can i send email without showing intent to user @yuku i want to send password to email – Erum Feb 07 '15 at 09:14
-
@erdomester, I've seen this happen on an Android 4.1.1 emulator when the default email client isn't configured with an email account. Maybe this just means no matching activities were found. – Sam Jun 25 '15 at 10:54
-
@erdomester, interestingly, this doesn't happen if you use the `setType` approach instead of this one. – Sam Jun 25 '15 at 11:30
-
@erdomester, further testing suggests this is just a problem with the official Android emulators. – Sam Jun 25 '15 at 13:01
-
Wrong. I never test on emulators, cause I use real phones. Also, emulators make my notebook extremely slow (but eclipse or studio both make it very slow) even if I have 8GB RAM, 4 processors and the notebook is in perfect condition. – erdomester Jun 26 '15 at 18:21
-
@erdomester, on what device did the problem happen for you? I haven't been able to produce it on any real devices. – Sam Sep 25 '15 at 21:06
-
The reason you are getting the "No app can perform this action" is because you did not add setData to your intent. Add that, and leave the "mailto:" without an email address to resolve. Text/Play type is better because it filters out unnecessary email clients. – portfoliobuilder Oct 27 '15 at 18:12
-
Thank you! This is the only solution worked for me. All others didn't work on devices without sd card – Dec 16 '15 at 08:31
-
2This answer is [quite influential](https://www.google.com/?q="this+will+make+such+that+when+user+returns+to+your+app,+your+app+is+displayed,+instead+of+the+email+app"&gws_rd=cr&ei=BWXHWOqDNoStsAHp-634BA#newwindow=1&q="this+will+make+such+that+when+user+returns+to+your+app,+your+app+is+displayed,+instead+of+the+email+app"). :) – Nick Volynkin Mar 14 '17 at 03:36
-
You call setData() after setType() here. It has no sense as calling setData() will erase any type set before. So, just remove setType() and it will work the same. – Prizoff Jul 25 '19 at 14:00
-
@Prizoff wow, thanks for this updated information! I will remove the setType from the answer. Ref from Android docs: > Set the data this intent is operating on. This method automatically clears any type that was previously set by setType(String) – Randy Sugianto 'Yuku' Aug 13 '19 at 04:13
-
I was using something along the lines of the currently accepted answer in order to send emails with an attached binary error log file. GMail and K-9 send it just fine and it also arrives fine on my mail server. The only problem was my mail client of choice Thunderbird which had troubles with opening / saving the attached log file. In fact it simply didn't save the file at all without complaining.
I took a look at one of these mail's source codes and noticed that the log file attachment had (understandably) the mime type message/rfc822
. Of course that attachment is not an attached email. But Thunderbird cannot cope with that tiny error gracefully. So that was kind of a bummer.
After a bit of research and experimenting I came up with the following solution:
public Intent createEmailOnlyChooserIntent(Intent source,
CharSequence chooserTitle) {
Stack<Intent> intents = new Stack<Intent>();
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
"info@example.com", null));
List<ResolveInfo> activities = getPackageManager()
.queryIntentActivities(i, 0);
for(ResolveInfo ri : activities) {
Intent target = new Intent(source);
target.setPackage(ri.activityInfo.packageName);
intents.add(target);
}
if(!intents.isEmpty()) {
Intent chooserIntent = Intent.createChooser(intents.remove(0),
chooserTitle);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
intents.toArray(new Parcelable[intents.size()]));
return chooserIntent;
} else {
return Intent.createChooser(source, chooserTitle);
}
}
It can be used as follows:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("*/*");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(crashLogFile));
i.putExtra(Intent.EXTRA_EMAIL, new String[] {
ANDROID_SUPPORT_EMAIL
});
i.putExtra(Intent.EXTRA_SUBJECT, "Crash report");
i.putExtra(Intent.EXTRA_TEXT, "Some crash report details");
startActivity(createEmailOnlyChooserIntent(i, "Send via email"));
As you can see, the createEmailOnlyChooserIntent method can be easily fed with the correct intent and the correct mime type.
It then goes through the list of available activities that respond to an ACTION_SENDTO mailto
protocol intent (which are email apps only) and constructs a chooser based on that list of activities and the original ACTION_SEND intent with the correct mime type.
Another advantage is that Skype is not listed anymore (which happens to respond to the rfc822 mime type).

- 23,933
- 14
- 88
- 109

- 5,392
- 1
- 33
- 39
-
1i just inserted you code snippet and it works fine. Before there have been listed apps like Google Drive, Skype etc. But isn't there a way to send a mail out of the application without calling another application? i just read the article about the email client that @Rene postet above but seems to be too complicated for just sending a simple email – Alex Cio Jan 18 '13 at 19:29
-
Excellent answer. I had Skype and Google Drive coming up with `ACTION_SEND` as well and this sorts it out beautifully. – darrenp Sep 04 '13 at 18:45
-
1The most popular solution above returns Skype and Vkontakte as well. This solution is better. – Denis Kutlubaev Dec 26 '13 at 17:18
-
-
@Noufal This is just some remainder from my own code base. It's a `File` instance pointing to a crash log file my Android apps create in the background in case there was an uncaught exception. That example should just illustrate how to add an email attachment. You could also attach any other file from the external storage (an image for example). You can also remove that line with `crashLogFile` in order to get a working example. – tiguchi Feb 06 '14 at 15:06
-
Works for me as well. The accepted answer was including options like Skype and Google Drive which carry some problems: the problem with the Skype option was that you'd get a `'You can only send files stored on your device.'` message when trying to send the file; with Google Drive it would use the `EXTRA_SUBJECT` as the default file name instead of the actual file's name. – user1987392 May 06 '16 at 14:58
-
Creative and works well to filter out undesirable apps. Needs more upvotes! – kaay Dec 14 '17 at 09:28
To JUST LET EMAIL APPS to resolve your intent you need to specify ACTION_SENDTO as Action and mailto as Data.
private void sendEmail(){
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:" + "recipient@example.com")); // You can use "mailto:" if you don't know the address beforehand.
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My email's subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "My email's body");
try {
startActivity(Intent.createChooser(emailIntent, "Send email using..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Activity.this, "No email clients installed.", Toast.LENGTH_SHORT).show();
}
}
The solution to this is simple: the android documentation explains it.
(https://developer.android.com/guide/components/intents-common.html#Email)
The most important is the flag: it is ACTION_SENDTO
, and not ACTION_SEND
The other important line is
intent.setData(Uri.parse("mailto:")); ***// only email apps should handle this***
By the way, if you send an empty Extra
, the if()
at the end won't work and the app won't launch the email client.
According to Android documentation. If you want to ensure that your intent is handled only by an email app (and not other text messaging or social apps), then use the ACTION_SENDTO
action and include the "mailto:
" data scheme. For example:
public void composeEmail(String[] addresses, String subject) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:")); // only email apps should handle this
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}

- 2,296
- 1
- 26
- 32
The strategy of using .setType("message/rfc822")
or ACTION_SEND
seems to also match apps that aren't email clients, such as Android Beam and Bluetooth.
Using ACTION_SENDTO
and a mailto:
URI seems to work perfectly, and is recommended in the developer documentation. However, if you do this on the official emulators and there aren't any email accounts set up (or there aren't any mail clients), you get the following error:
Unsupported action
That action is not currently supported.
As shown below:
It turns out that the emulators resolve the intent to an activity called com.android.fallback.Fallback
, which displays the above message. Apparently this is by design.
If you want your app to circumvent this so it also works correctly on the official emulators, you can check for it before trying to send the email:
private void sendEmail() {
Intent intent = new Intent(Intent.ACTION_SENDTO)
.setData(new Uri.Builder().scheme("mailto").build())
.putExtra(Intent.EXTRA_EMAIL, new String[]{ "John Smith <johnsmith@yourdomain.com>" })
.putExtra(Intent.EXTRA_SUBJECT, "Email subject")
.putExtra(Intent.EXTRA_TEXT, "Email body")
;
ComponentName emailApp = intent.resolveActivity(getPackageManager());
ComponentName unsupportedAction = ComponentName.unflattenFromString("com.android.fallback/.Fallback");
if (emailApp != null && !emailApp.equals(unsupportedAction))
try {
// Needed to customise the chooser dialog title since it might default to "Share with"
// Note that the chooser will still be skipped if only one app is matched
Intent chooser = Intent.createChooser(intent, "Send email with");
startActivity(chooser);
return;
}
catch (ActivityNotFoundException ignored) {
}
Toast
.makeText(this, "Couldn't find an email app and account", Toast.LENGTH_LONG)
.show();
}
Find more info in the developer documentation.

- 40,644
- 36
- 176
- 219
Sending email can be done with Intents which will require no configuration. But then it will require user interaction and the layout will be a bit restricted.
Build and sending a more complex email without user interaction entails building your own client. The first thing is that the Sun Java API for email are unavailable. I have had success leveraging the Apache Mime4j library to build email. All based on the docs at nilvec.

- 4,170
- 1
- 25
- 40

- 4,033
- 2
- 24
- 29
Here is the sample working code which opens mail application in android device and auto-filled with To address and Subject in the composing mail.
protected void sendEmail() {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:feedback@gmail.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "Feedback");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}

- 527
- 8
- 9
-
Thanks. Comparing with a solution of @Avi Parshan, you set an email in `setData()`, and Avi sets in `putExtra()`. Both variants a working. But if remove `setData` and use only `intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"hi@example.com"});`, there would be a `ActivityNotFoundException`. – CoolMind Apr 16 '18 at 16:13
I use the below code in my apps. This shows exactly email client apps, such as Gmail.
Intent contactIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", getString(R.string.email_to), null));
contactIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
startActivity(Intent.createChooser(contactIntent, getString(R.string.email_chooser)));

- 9,412
- 15
- 70
- 85
This will show you only the email clients (as well as PayPal for some unknown reason)
public void composeEmail() {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"hi@example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Body");
try {
startActivity(Intent.createChooser(intent, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}

- 2,131
- 2
- 24
- 36
-
1Nice solution! It avoids many unsuitable applications (mostly used as "Share"). Don't add `intent.type = "message/rfc822"; intent.type = "text/html";` here as it will lead to exception. – CoolMind Apr 15 '18 at 23:26
This is how I did it. Nice and simple.
String emailUrl = "mailto:email@example.com?subject=Subject Text&body=Body Text";
Intent request = new Intent(Intent.ACTION_VIEW);
request.setData(Uri.parse(emailUrl));
startActivity(request);

- 618
- 1
- 6
- 18
I used this code to send mail by launching default mail app compose section directly.
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setType("message/rfc822");
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"test@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

- 970
- 13
- 17
This function first direct intent gmail for sending email, if gmail is not found then promote intent chooser. I used this function in many commercial app and it's working fine. Hope it will help you:
public static void sentEmail(Context mContext, String[] addresses, String subject, String body) {
try {
Intent sendIntentGmail = new Intent(Intent.ACTION_VIEW);
sendIntentGmail.setType("plain/text");
sendIntentGmail.setData(Uri.parse(TextUtils.join(",", addresses)));
sendIntentGmail.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
sendIntentGmail.putExtra(Intent.EXTRA_EMAIL, addresses);
if (subject != null) sendIntentGmail.putExtra(Intent.EXTRA_SUBJECT, subject);
if (body != null) sendIntentGmail.putExtra(Intent.EXTRA_TEXT, body);
mContext.startActivity(sendIntentGmail);
} catch (Exception e) {
//When Gmail App is not installed or disable
Intent sendIntentIfGmailFail = new Intent(Intent.ACTION_SEND);
sendIntentIfGmailFail.setType("*/*");
sendIntentIfGmailFail.putExtra(Intent.EXTRA_EMAIL, addresses);
if (subject != null) sendIntentIfGmailFail.putExtra(Intent.EXTRA_SUBJECT, subject);
if (body != null) sendIntentIfGmailFail.putExtra(Intent.EXTRA_TEXT, body);
if (sendIntentIfGmailFail.resolveActivity(mContext.getPackageManager()) != null) {
mContext.startActivity(sendIntentIfGmailFail);
}
}
}

- 4,391
- 1
- 33
- 39
This is the most clean way of sending email on Android.
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf("email@example.com"))
putExtra(Intent.EXTRA_SUBJECT, "Subject")
putExtra(Intent.EXTRA_TEXT, "Email body")
}
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
You also need to specify in your manifest (outside your application tag) the query for applications that handle email (mailto)
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
If you need to send HTML text in the email body, please replace the "Email body" with your email string, something like this (please beware that Html.fromHtml maybe deprecated this was only for show you how to do it)
Html.fromHtml(
StringBuilder().append("<b>Hello world</b>").toString()
)

- 23,933
- 14
- 88
- 109

- 2,530
- 4
- 20
- 32
simple try this one
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buttonSend = (Button) findViewById(R.id.buttonSend);
textTo = (EditText) findViewById(R.id.editTextTo);
textSubject = (EditText) findViewById(R.id.editTextSubject);
textMessage = (EditText) findViewById(R.id.editTextMessage);
buttonSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String to = textTo.getText().toString();
String subject = textSubject.getText().toString();
String message = textMessage.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
// email.putExtra(Intent.EXTRA_CC, new String[]{ to});
// email.putExtra(Intent.EXTRA_BCC, new String[]{to});
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, message);
// need this to prompts email client only
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Choose an Email client :"));
}
});
}

- 8,621
- 10
- 63
- 98
-
3How is this any better than the answers that already existed when you posted this? It just looks like a copy of the accepted answer wrapped in an activity. – Sam Jun 25 '15 at 13:03
Other solution can be
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("plain/text");
emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"someone@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Yo");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hi");
startActivity(emailIntent);
Assuming most of the android device has GMail app already installed.

- 6,730
- 6
- 39
- 81
-
-
1Yes we can. But your solution is no the right one. The Android documentation states clearly what you have to do in order to show only mail apps in the intent chooser. You wrote "Assuming most of the android device has Gmail app already installed"; What if it is a rooted device and the user delete Gmail client?. Suppose you are creating your own email app?, if a user is going to send a e-mail your app won't be in that list. What happen if gmail change the package name? Are you going to update your app? – Pedro Varela Aug 23 '16 at 18:20
Use this for send email...
boolean success = EmailIntentBuilder.from(activity)
.to("support@example.org")
.cc("developer@example.org")
.subject("Error report")
.body(buildErrorReport())
.start();
use build gradle :
compile 'de.cketti.mailto:email-intent-builder:1.0.0'

- 234
- 2
- 13
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","ebgsoldier@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Forgot Password");
emailIntent.putExtra(Intent.EXTRA_TEXT, "this is a text ");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

- 129
- 6
This method work for me. It open Gmail app (if installed) and set mailto.
public void openGmail(Activity activity) {
Intent emailIntent = new Intent(Intent.ACTION_VIEW);
emailIntent.setType("text/plain");
emailIntent.setType("message/rfc822");
emailIntent.setData(Uri.parse("mailto:"+activity.getString(R.string.mail_to)));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, activity.getString(R.string.app_name) + " - info ");
final PackageManager pm = activity.getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
ResolveInfo best = null;
for (final ResolveInfo info : matches)
if (info.activityInfo.packageName.endsWith(".gm") || info.activityInfo.name.toLowerCase().contains("gmail"))
best = info;
if (best != null)
emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
activity.startActivity(emailIntent);
}

- 41
- 1
- 3
/**
* Will start the chosen Email app
*
* @param context current component context.
* @param emails Emails you would like to send to.
* @param subject The subject that will be used in the Email app.
* @param forceGmail True - if you want to open Gmail app, False otherwise. If the Gmail
* app is not installed on this device a chooser will be shown.
*/
public static void sendEmail(Context context, String[] emails, String subject, boolean forceGmail) {
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL, emails);
i.putExtra(Intent.EXTRA_SUBJECT, subject);
if (forceGmail && isPackageInstalled(context, "com.google.android.gm")) {
i.setPackage("com.google.android.gm");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
try {
context.startActivity(Intent.createChooser(i, "Send mail..."));
} catch (ActivityNotFoundException e) {
Toast.makeText(context, "No email app is installed on your device...", Toast.LENGTH_SHORT).show();
}
}
}
/**
* Check if the given app is installed on this devuice.
*
* @param context current component context.
* @param packageName The package name you would like to check.
* @return True if this package exist, otherwise False.
*/
public static boolean isPackageInstalled(@NonNull Context context, @NonNull String packageName) {
PackageManager pm = context.getPackageManager();
if (pm != null) {
try {
pm.getPackageInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
return false;
}

- 6,221
- 3
- 41
- 33
Try this:
String mailto = "mailto:bob@example.org" +
"?cc=" + "alice@example.com" +
"&subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(bodyText);
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));
try {
startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
//TODO: Handle case where no email app is available
}
The above code will open the users favourite email client prefilled with the email ready to send.

- 7,242
- 3
- 52
- 70
Kotlin version which only shows Email clients (no contacts etc.):
with(Intent(Intent.ACTION_SEND)) {
type = "message/rfc822"
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf("user@example.com"))
putExtra(Intent.EXTRA_SUBJECT,"YOUR SUBJECT")
putExtra(Intent.EXTRA_TEXT, "YOUR BODY")
try {
startActivity(Intent.createChooser(this, "Send Email with"))
} catch (ex: ActivityNotFoundException) {
// No email clients found, might show Toast here
}
}

- 23,933
- 14
- 88
- 109

- 5,598
- 2
- 22
- 29
The code below works on Android 10 devices and higher. It also sets the subject, body and recipient(To).
val uri = Uri.parse("mailto:$EMAIL")
.buildUpon()
.appendQueryParameter("subject", "App Feedback")
.appendQueryParameter("body", "Body Text")
.appendQueryParameter("to", EMAIL)
.build()
val emailIntent = Intent(Intent.ACTION_SENDTO, uri)
startActivity(Intent.createChooser(emailIntent, "Select app"))

- 45
- 7
Filtering for 'real' E-Mail Apps is still an issue today. As many people mentioned above, other apps nowadays also report to support the mime-type "message/rfc822". Therefore, this mime-type is not suitable any more to filter for a real E-Mail App.
If you want to send a simple text mail, it is enough to use the the ACTION_SENDTO
intent action with the appropriate data type like so:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, text);
Intent chooser = Intent.createChooser(intent, "Send Mail");
context.startActivity(chooser);
This will filter all available apps for those that support the 'mailto' protocol, which is much more suitable for the purpose of sending an E-mail.
But sadly things become complicated, if you want to send a mail with (multiple) attachments. The ACTION_SENDTO action does not support the EXTRA_STREAM
extra on the intent. If you want to use that, you must use the ACTION_SEND_MULTIPLE
action, which does not work together with the the data type Uri.parse("mailto:").
For now I found a solution, which consists of the following steps:
- Declare that your App wants to query Apps on the device, that support the mailto protocol (important for all Apps since Android 11)
- Actually query all Apps, that support the mailto protocol
- For each supporting App: Build the intent that you actually want to launch, aiming for that single App
- Build the App chooser and launch it
And this is how it looks in code:
Add this to the AndroidManifest:
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
This is the Java code:
/* Query all Apps that support the 'mailto' protocol */
PackageManager pm = context.getPackageManager();
Intent emailCheckerIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
List<ResolveInfo> emailApps = pm.queryIntentActivities(emailCheckerIntent, PackageManager.MATCH_DEFAULT_ONLY);
/* For each supporting App: Build an intent with the desired values */
List<Intent> intentList = new ArrayList<>();
for (ResolveInfo resolveInfo : emailApps) {
String packageName = resolveInfo.activityInfo.packageName;
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setPackage(packageName);
intent.setComponent(new ComponentName(packageName, resolveInfo.activityInfo.name));
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.putExtra(Intent.EXTRA_STREAM, attachmentUris);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //IMPORTANT to give the E-Mail App access to your attached files
intentList.add(intent);
}
/* Create a chooser consisting of the queried apps only */
Intent chooser = Intent.createChooser(intentList.remove(intentList.size() - 1), "Send Mail");
Intent[] extraIntents = intentList.toArray(new Intent[0]);
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
context.startActivity(chooser);
Note: If the itentList
only has one item, Android will automatically skip the chooser and run the only App automatically.

- 31
- 2
import androidx.core.app.ShareCompat
import androidx.core.content.IntentCompat
ShareCompat.IntentBuilder(this)
.setType("message/rfc822")
.setEmailTo(arrayOf(email))
.setStream(uri)
.setSubject(subject)
.setText(message + emailMessage)
.startChooser()

- 755
- 8
- 19