• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Problem in Java Mail using Servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
set your form attribute ENCTYPE="multipart/form-data", and then in servlet download your file to local machine and then send it as attachement.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[hi-jack removed]
[ December 22, 2006: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Talha-bin -Shakir,

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

Thank you,
-Ben
reply
    Bookmark Topic Watch Topic
  • New Topic