This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Send Multiple Attachments In An Email

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anybody tell me that how to send more than one file in attachment of email using java mail api.

In my case the number of attachment is not fixed. But i have to pick it up from one given location.
Like location of folder is : d:\backup
now in backup folder there may be more than one file, which i need to attach.

Please help me.

Thanks,
Kaya.
 
karimkhan pathan
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use javax.mail.Multipart and addbodypart method for adding attachment using java mail api .

Hope this helps ..
 
Nishita Jain
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setText(message);
multipart.addBodyPart(messageBodyPart);

//attachment...
messageBodyPart = new MimeBodyPart();

String fileAttachment = "D:\\timer.txt";
DataSource source = new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler( new DataHandler(source));
messageBodyPart.setFileName("a1.txt");
multipart.addBodyPart(messageBodyPart);

//second attachment
MimeBodyPart messageBodyPart2 = new MimeBodyPart();
DataSource source2 = new FileDataSource("D:\\searchQuery.txt");
messageBodyPart2.setDataHandler( new DataHandler(source2));
messageBodyPart2.setFileName("a2.txt");
multipart.addBodyPart(messageBodyPart2);
. . .

msg.setContent(multipart);

Hope this is helpful

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic