• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send an attachment?

 
Neela Sathesh
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friend
I am using jsp to send mail(using javaMail) and it is working. now i am in need of sending an attachment with it. Please send ur suggestions for the same.
Thank u.
 
Riddhi Shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to try our the following code. You can create a mimebodypart object for attachment and then attach it to the multipartbody.
String fileName = "your filename";
MimeBodyPart attachmentPart=new MimeBodyPart();
MimeBodyPart mBodyPart = new MimeBodyPart();
mBodyPart.setContent(multipartBody);
attachmentPart=new MimeBodyPart();
DataSource dataSource = new FileDataSource(fileName);
attachmentPart.setDataHandler(new DataHandler(dataSource));
attachmentPart.setFileName(fileName);
multipartBody.addBodyPart(attachmentPart);
Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!