Send Email Intent

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");

startActivity(Intent.createChooser(intent, "Send Email"));

The above code opens a dialog showing following apps:- Bluetooth, Google Docs, Yahoo Mail, Gmail, Orkut, Skype etc.

Actually, I want to filter these list-options. I want to show only email related apps eg Gmail, Yahoo Mail. How to do it?

I've seen such example on 'Android Market' application.

  • Open Android Market app
  • Open any application where developer has specified his/her email address. (If you can't find such app just open my app:- market://details?id=com.becomputer06.vehicle.diary.free , OR search by 'Vehicle Diary')
  • Scroll down to 'DEVELOPER'
  • Click on 'Send Email'
  • The dialog shows only email Apps eg Gmail, Yahoo Mail etc. It does not show Bluetooth, Orkut etc. What code produces such dialog?


    when you will change your intent.setType like below you will get

    intent.setType("text/plain");
    

    Use android.content.Intent.ACTION_SENDTO to get only the list of e-mail clients, with no facebook or other apps. Just the email clients. Ex:

    new Intent(Intent.ACTION_SENDTO);
    

    I wouldn't suggest you get directly to the email app. Let the user choose his favorite email app. Don't constrain him.

    If you use ACTION_SENDTO, putExtra does not work to add subject and text to the intent. Use Uri to add the subject and body text.

    EDIT: We can use message/rfc822 instead of "text/plain" as the MIME type. However, that is not indicating "only offer email clients" -- it indicates "offer anything that supports message/rfc822 data". That could readily include some application that are not email clients.

    message/rfc822 supports MIME Types of .mhtml, .mht, .mime


    The accepted answer doesn't work on the 4.1.2. This should work on all platforms:

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                "mailto","abc@gmail.com", null));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
    startActivity(Intent.createChooser(emailIntent, "Send email..."));
    

    Hope this helps.

    Update: According to marcwjj, it seems that on 4.3, we need to pass string array instead of a string for email address to make it work. We might need to add one more line:

    intent.putExtra(Intent.EXTRA_EMAIL, addresses); // String[] addresses
    

    Ref link


    There are three main approaches:

    String email = /* Your email address here */
    String subject = /* Your subject here */
    String body = /* Your body here */
    String chooserTitle = /* Your chooser title here */
    

    1. Custom Uri :

    Uri uri = Uri.parse("mailto:" + email)
        .buildUpon()
        .appendQueryParameter("subject", subject)
        .appendQueryParameter("body", body)
        .build();
    
    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, uri);
    startActivity(Intent.createChooser(emailIntent, chooserTitle));
    

    2. Using Intent extras:

    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
    //emailIntent.putExtra(Intent.EXTRA_HTML_TEXT, body); //If you are using HTML in your body text
    
    startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
    

    3. Support Library ShareCompat :

    Activity activity = /* Your activity here */
    
    ShareCompat.IntentBuilder.from(activity)
        .setType("message/rfc822")
        .addEmailTo(email)
        .setSubject(subject)
        .setText(body)
        //.setHtmlText(body) //If you are using HTML in your body text
        .setChooserTitle(chooserTitle)
        .startChooser();
    
    链接地址: http://www.djcxy.com/p/23258.html

    上一篇: 使用默认的Android应用程序(Builtin Email应用程序)在Android中发送电子邮件

    下一篇: 发送电子邮件意向