dcsimg
Client browsers are unable to add attachments to emails
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Craig_Pettie
Posted On:   Tuesday, March 7, 2006 08:07 PM

I've setup a jsp to process a preceding page's form content (including the path of a file to attach to an email). When running the jsp's on my localhost the file is attached and sent with the email. When other client's try to attach a file I receive the following exception: javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: IOException while sending message;nested exception is: java.io.FileNotFoundException: No such path or directory. The first page looks like this... Competition <%=competition%>"> First Name: Last Name:    More>>

I've setup a jsp to process a preceding page's form content (including the path of a file to attach to an email). When running the jsp's on my localhost the file is attached and sent with the email. When other client's try to attach a file I receive the following exception:

javax.mail.SendFailedException: Sending failed; nested exception is: javax.mail.MessagingException: IOException while sending message;nested exception is: java.io.FileNotFoundException: No such path or directory.



The first page looks like this...


			


Competition

<%=competition%>">

First Name:



Last Name:



Attach Resume (optional):













The 'sendApplication' page looks like this...


			
strCompetition = request.getParameter("competition").toString();

strFirstName = request.getParameter("firstName").toString();

strLastName = request.getParameter("lastName").toString();

strFilename = request.getParameter("file");


//Create the body of the email

strBody = "Competition:" + strCompetition + " Name:" +
strFirstName + " " + strLastName;


Properties props = new Properties();

props.put("mail.smtp.host", "smtp");


Session s = Session.getInstance(props, null);

MimeMessage message = new MimeMessage(s);


InternetAddress from = new InternetAddress("email_address", "HR_from");

InternetAddress to = new InternetAddress("email_address");


//Build the email

message.setFrom(from);

message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Competition: " + strCompetition + " - " + strFirstName + " " + strLastName);


BodyPart messageBodyPart = new MimeBodyPart();


// Fill the message body text

messageBodyPart.setContent(strBody, "text/html");


Multipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);

//// Add the attachment

messageBodyPart = new MimeBodyPart();


FileDataSource source = new FileDataSource(strFilename);

messageBodyPart.setDataHandler(new DataHandler(source));

multipart.addBodyPart(messageBodyPart);


//// Compose Message

message.setContent(multipart);


//Send the email

Transport.send(message);


--------------


Any help would be appreciated. I suspect that there is something to do with the relative path vs. setting an absolute path or something but I frankly don't know.

   <<Less

Re: Client browsers are unable to add attachments to emails

Posted By:   Lunkwill_Vroomfondel  
Posted On:   Monday, April 10, 2006 08:49 AM

set the form's enctype:



enctype="multipart/form-data"



then you would also have the get the sent-data not simply as request.getParameter, but you have to use a "multipart-servlet"


i usually use some of this:


http://servlets.com/cos/javadoc/com/oreilly/servlet/MultipartWrapper.html
About | Sitemap | Contact