Hannelore
Hannelore

Reputation: 763

Android open emailclient programmatically

Is it possible to open an emailclient such as gmail when I click a button in my app?

Upvotes: 14

Views: 11742

Answers (5)

Monir Zzaman
Monir Zzaman

Reputation: 489

You can simply use below code when for no attachment:

Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:[email protected]")); 
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
startActivity(Intent.createChooser(emailIntent, "Send feedback"));

For details I recommend to visit: https://developer.android.com/guide/components/intents-common.html#Email

Upvotes: 0

Guri S
Guri S

Reputation: 1103

This Worked fine for me

Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"[email protected]"} );
                shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
                startActivity(Intent.createChooser(shareIntent, "Share "));

Upvotes: 0

AkshayT
AkshayT

Reputation: 3021

If above code is not working then try this. Tested and working

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.item/email"); 
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
startActivity(Intent.createChooser(intent, "Send mail using..."));

Upvotes: 0

Jono
Jono

Reputation: 18128

Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto", EMAIL_ADDRESS, null));

up to date way of doing it

        i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
        i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
        startActivity(Intent.createChooser(i, "Send email"));

Upvotes: 6

Robby Pond
Robby Pond

Reputation: 73494

Yes. You can launch it via Intents.

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));

Upvotes: 28

Related Questions