Attachment is not coming in mail programmatically

I am attaching a TEXT file to Email with code :

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

    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Report");

    emailIntent.putExtra(Intent.EXTRA_TEXT, prepareBodyMail());
    File root = Environment.getExternalStorageDirectory();
    File file = new File(root, "/MyFolder/report.txt");

    Uri uri = Uri.fromFile(file);
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));

This code works perfectly with Gmail, Email and other apps

  • Android Studio Git .gitignore vs Project > Settings > Version Control > Ignored Files
  • Play store Beta Testing doesn't work
  • swap fragment in an activity via animation
  • Charles proxy fails on SSL Connect Method
  • Tutorial for android application with PHONEGAP
  • Failure on build with Gradle on command line with an android studio project : Xlint error
  • But this is not attaching file with INBOX application by Google

    Only Body and subject are coming without any attachment

    I have reported this problem to Google Groups at Inbox Problem

    Can anybody help what I am missing in code?

  • Should I learn Java before learning Android
  • Android Material Design: Failed to find style 'toolbarStyle' in current theme
  • IllegalArgumentException: Service not registered:
  • Avoid passing null as the view root (need to resolve layout parameters on the inflated layout's root element)
  • IllegalStateException: Can't change tag of fragment was android:switcher now android:switcher
  • Margin inside buttons
  • 4 Solutions collect form web for “Attachment is not coming in mail programmatically”

    Try this

         Uri myUri = Uri.parse("file://" + path);
         emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
    String fileLocation = Environment.getExternalStorageDirectory() + "/MyFolder/report.txt";    
    String to[] = {""};
    Intent intentEmail = new Intent(Intent.ACTION_SEND);
    intentEmail.putExtra(Intent.EXTRA_EMAIL, to);
    intentEmail.putExtra(Intent.EXTRA_STREAM, fileLocation);
    intentEmail.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    startActivity(Intent.createChooser(intentEmail , "Pick an Email provider"));
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] {""});
    intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
    intent.putExtra(Intent.EXTRA_TEXT, "body text");
    File root = Environment.getExternalStorageDirectory();
    File file = new File(root, xmlFilename);
    if (!file.exists() || !file.canRead()) {
        Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
    Uri uri = Uri.fromFile("file://" + file);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(intent, "Send email..."));
      public void sendMailWithIntent(String emailTo,
                                       String subject, String emailText, List<String> filePaths) {
            try {
                //need to "send multiple" to get more than one attachment
                final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
    //            emailIntent.putExtra(android.content.Intent.EXTRA_CC,
    //                    new String[]{emailCC});
                emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
                ArrayList<Uri> uris = new ArrayList<Uri>();
                //has to be an ArrayList
                if (filePaths != null) {
                    //convert from paths to Android friendly Parcelable Uri's
                    for (String file : filePaths) {
                        File fileIn = new File(file);
                        Uri u = Uri.fromFile(fileIn);
                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                Intent chooser = Intent.createChooser(emailIntent, "Send mail...");
                activity.startActivityForResult(chooser, 1);
            } catch (Exception e) {
                new ShowToast(context, e.getMessage());

    Call method

        List<String> list = new ArrayList<>();
        sendMailWithIntent(toAddresses, subject, body, list);
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.