title: send mail with MS Excel file (from sdCard) attachment programmatically in android
body: <p>after a few researches I managed to send emails programmatically from my app directly by following those steps <a href="https://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a/2033124#2033124">here</a> and without launching any mails app</p>
  
  <p>but now I want to add a MS Excel file as attachment</p>
  
  <p>and I don't know how</p>
  
  <p>as I have understood from this code:</p>
  
  <pre><code>   public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {   
      try{
      MimeMessage message = new MimeMessage(session);   
      DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));   
      message.setSender(new InternetAddress(sender));   
      message.setSubject(subject);   
      message.setDataHandler(handler);   
      if (recipients.indexOf(',') &gt; 0)   
          message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
      else  
          message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));   
      Transport.send(message);   
      }catch(Exception e){
  
      }
  }
  </code></pre>
  
  <p>I call the above method in a background asynctask to send the message but is there any way to add MS Excel file attachment</p>