-7

I have working code to send only one Attachment, but I want to send multiple attachments, please let me how if I can send multiple attachments with this 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); 
  } 
o-90
  • 17,045
  • 10
  • 39
  • 63
  • seems no effort !! can you plz provide some explanation about ur issue ? any error logs etc . @Awesh – Radhey Oct 08 '15 at 06:40
  • As i am new to Android, I wanted to send multiple attachments, and the code above is for single attachment. If it os possible Please suggest me what i should have to do for that?, – Awesh Vishwakarma Oct 08 '15 at 06:45
  • not an issue . plz refer http://stackoverflow.com/questions/3177616/how-to-attach-multiple-files-to-an-email-using-javamail . except the answer if it will use full to you. – Radhey Oct 08 '15 at 06:47
  • Thank You For The Link... It Will Help Me.. Thanx alot... – Awesh Vishwakarma Oct 08 '15 at 06:50

1 Answers1

0

you can alternatively write code like this ,

Multipart _multipart = new MimeMultipart("test");
for (String str : attachment_List) {
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(str);
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(source.getName());
    multipart.addBodyPart(messageBodyPart);
}
_msg.setContent(_multipart);
Transport.send(_msg);
Radhey
  • 2,139
  • 2
  • 24
  • 42