aspose file tools*
The moose likes Servlets and the fly likes Problem in Java Mail using Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in Java Mail using Servlet" Watch "Problem in Java Mail using Servlet" New topic
Author

Problem in Java Mail using Servlet

Harsh Sahajwani
Greenhorn

Joined: Dec 21, 2006
Posts: 1
Hi,

I am using an html form to be filled in and a servlet to get parameters from the html form. The servlet then uses the Java Mail API to attach the file and send the mail.

The problem I am facing is that when I deploy the application on server on my local machine, the servlet gets the file location from html form, searches it on my local machine, attaches it with mail and sends it. But when I use a server installed and running on different machine on network, the servlet gets the file name from the html form, searches that file on the machine on which server is running (and not on my local machine), and fails to attach the file, and mail sending gets failed. Is there any solution to my problem? The servlet code that I am using is as follows:

Thanks,

Harsh

[BSouther: Added UBB CODE tags]
[ December 22, 2006: Message edited by: Ben Souther ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42931
    
  68
Welcome to JavaRanch.

The server won't be able to access a file on the client directly. Instead of entering the name of the file, use a file upload element in the HTML form. Then you can use the Commons FileUpload to extract the file contents from the other form data.
pawank gupta
Ranch Hand

Joined: Jun 07, 2006
Posts: 34
set your form attribute ENCTYPE="multipart/form-data", and then in servlet download your file to local machine and then send it as attachement.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by pawank gupta:
set your form attribute ENCTYPE="multipart/form-data", and then in servlet download your file to local machine and then send it as attachement.


Just changing the enctype of the form is not enough.
Servlets (out of the box) can't handle multipart form data.
This is why Ulf posted the link to commons/fileupload.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Talha-bin -Shakir
Ranch Hand

Joined: Jan 26, 2006
Posts: 32
[hi-jack removed]
[ December 22, 2006: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Talha-bin -Shakir,

Please do not hi-jack other people's threads.
If you have a question, start your own.

Thank you,
-Ben
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Java Mail using Servlet