Android mail without intents using Android Mail API
<p>I am using an function to attach image to an email.</p>

<pre><code> public void addAttachment(String filename) throws Exception { 
    BodyPart messageBodyPart = new MimeBodyPart(); 
    DataSource source = new FileDataSource(filename); 
    messageBodyPart.setDataHandler(new DataHandler(source)); 
    messageBodyPart.setFileName(filename); 

    _multipart.addBodyPart(messageBodyPart); 

  } 
</code></pre>

<p>I call this function when attaching images to email.
When I try to remove the attachment it is not possible.</p>

<pre><code> public void removeAttachment(String filename) throws Exception { 
    BodyPart messageBodyPart = new MimeBodyPart(); 
    DataSource source = new FileDataSource(filename); 
    messageBodyPart.setDataHandler(new DataHandler(source)); 
    messageBodyPart.setFileName(filename); 

    _multipart.removeBodyPart(messageBodyPart); 

  } 
</code></pre>

<p>Tried with this function but not working.</p>

<pre><code> public void AddAndRemoveAttachment(String filename, Boolean yesorno)throws Exception{
      BodyPart messageBodyPart = new MimeBodyPart(); 
      DataSource source = new FileDataSource(filename); 
      if(yesorno == true ){

        source = new FileDataSource(filename); 
        messageBodyPart.setDataHandler(new DataHandler(source)); 
        messageBodyPart.setFileName(filename); 

        _multipart.addBodyPart(messageBodyPart); 
      }
      else{

          _multipart.removeBodyPart(messageBodyPart);
      }
  }
</code></pre>

<p>But the removeBodyPart is not removing the attached image.
Looking forward to your reply.
thanks.</p>
