This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to send email with multiple attachments  RSS feed

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi.... i want to send all files inside a particular folder as attachments.... can i do that using javamail api

Thnx in advance

-Rodricks
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yes. Though I'm not sure the recipient of an email with loads of attachements would thank you for doing it!

An amil with attachments is just a MIME multipart message, each part representing one attachement. Look at the attachFile method of MimeBodyPart.
 
Rodricks george
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Report post to moderator
File f = new File("e:\\mailFolder");
File[] attachments = f.listFiles();


Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);

// Part two is attachment
for( int i = 0; i < attachments.length; i++ ) {
messageBodyPart = new MimeBodyPart();
FileDataSource fileDataSource =new FileDataSource(attachments[i]);
messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
messageBodyPart.setFileName(attachments[i].getName());
multipart.addBodyPart(messageBodyPart);
}

// Put parts in message
message.setContent(multipart);

// Send the message
Transport.send( message );

its working fine
 
Marshal
Posts: 24506
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Report post to moderator
Amel MaGdo,
Your post was moved to a new topic.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!