title: Android - Sending TXT File as Attachment to Email Fails ("Couldn't send attachment")
body: <p>I am trying to get my Android app to send an e-mail with a file attached, and I'm starting out with a .txt file, since those are simple.</p>
  
  <p>So far I have this (taking place inside a Fragment):</p>
  
  <pre><code>//Send the email
  Intent mailIntent = new Intent(Intent.ACTION_SEND);
  mailIntent.setType("text/Message");
  mailIntent.putExtra(Intent.EXTRA_EMAIL  , new String[]{address});
  mailIntent.putExtra(Intent.EXTRA_SUBJECT, "Test Email");
  mailIntent.putExtra(Intent.EXTRA_TEXT   , "Hi!  This is a test!");
  
  //Deal with the attached report
  String FileName = "report.txt";
  Calculator.generateReport(getActivity().getApplicationContext(), FileName);
  //It will be called "report.txt"
  File attachment = getActivity().getApplicationContext().getFileStreamPath(FileName);
  if (!attachment.exists() || !attachment.canRead()) {
      Toast.makeText(getActivity().getApplicationContext(), 
                     "Attachment Error", 
                     Toast.LENGTH_SHORT).show();
      System.out.println("ATTACHMENT ERROR");
  }
  else
  {
      Uri uri = Uri.fromFile(attachment);
      mailIntent.putExtra(Intent.EXTRA_STREAM, uri);
  }
  
  //Send, if valid!
  try {
     startActivity(Intent.createChooser(mailIntent, "Send mail..."));
  } catch (android.content.ActivityNotFoundException ex) {
      Toast.makeText(getActivity().getApplicationContext(), 
                 "There are no email clients installed.", 
                 Toast.LENGTH_SHORT).show();
  }
  </code></pre>
  
  <p>Unfortunately, that doesn't seem to work.  Now I know the file exists; if I insert the appropriate code after <code>generateReport()</code>, I can find and access the file and read its contents.  It is there, and I have the right name.</p>
  
  <p>When I am given the option of choosing an email client, I pick Gmail and see that there is indeed a <code>report.txt</code> file attached to the email.  When I send the email, though, I get a notification stating "Couldn't send attachment", and the email arrives without anything attached.</p>
  
  <p>I should note that I have tried other intent types as well, such as <code>text/plain</code> and <code>message/rfc822</code>, to no avail.</p>
  
  <p>Any ideas on what I might be doing wrong?</p>