This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes send attachment Using JSP with JavaMail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "send attachment Using JSP with JavaMail" Watch "send attachment Using JSP with JavaMail" New topic
Author

send attachment Using JSP with JavaMail

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
How can I send an attachment using JSP with JavaMail?
I am able to send using only a text messge. which method from JavaMail API I can use in this?
Bhupinder Dhillon
Ranch Hand

Joined: Oct 12, 2000
Posts: 124
Multipart mp = new MimeMultipart();
//set email address(es)
...
...
//set message, if any
...
...
// create a message part
MimeBodyPart mbp = new MimeBodyPart();

// attach the file to the message part
FileDataSource fds = new FileDataSource(<full path to file> );
mbp.setDataHandler(new DataHandler(fds));
mbp.setFileName(fds.getName());
//mbp.setDisposition("inline");

// add this part to Multipart
mp.addBodyPart(mbp);
//more attachements, if any
....
....
//send it off using Transport
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"rajkumar",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: send attachment Using JSP with JavaMail
 
Similar Threads
jsp email
how to send more than one attachment with javamail
Image to String to Image in a email
How to send an attachment?
JAVAMAIL