How do I pick up the attachment from the client's machine, in a web-based email system?

Andrea Pompili

You can do it using an HTML form, a Servlet and the class MultipartRequest of the O'Reilly package avaiable at http://www.servlets.com/resources/com.oreilly.servlet/.
In this zip file (named cos.zip) you can found all the information you need to upload a file using a browser and a servlet.
Remember that the file you upload is stored in the server filesystem, so remember to remove it after sending your E-mail.

I tried also another way that worked perfectly, but is more complicated.
I wrote three classes :

  • A mine DataSource for handling a stream of byte with a filename and a content type
  • An ExtendedMultipartRequest class that extracts the parts from the stream of the Servlet (similar to the one provided by O'Reilly)
  • A MultipartInputStream for reading the InputStream of the servlet line by line
For creating a message I passed each data (bytes), content-type, and filename parsed by my ExtendedMultipartRequest class to my DataSource. Then I built a DataHandler using this DS and a Message using this as Content... It worked perfectly!!!
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.