java - How to send a non-local attachment with JavaMail -



java - How to send a non-local attachment with JavaMail -

i'm building application using jsp's, servlets, , fun stuff. right now, have form passes through info form html email sent using javamail api. works, trying send attachment, , way have set right not work...

<div class="section">upload files: <input id="fileupload" type="file" /></div>

i take input's value, pass through servlet , seek send email. problem when file sending, servlet cannot locate file because tag gives path

c:\fakepath\file.doc

any help amazing.

i figured out. fakepath security feature in browsers. happens though tomcat file stored in temp folder within tomcat folder. had play tomcat library, commons.fileupload, , used pull info file, regardless of fakepath location.

//handle file upload attachment servletfileupload servletfileupload = new servletfileupload(new diskfileitemfactory()); try{ list fileitemslist = servletfileupload.parserequest(request); //todo: take datafile input field , pass file name can view file name iterator = fileitemslist.iterator(); while (it.hasnext()){ fileitem fileitem = (fileitem)it.next(); if (fileitem.isformfield()){ /* file item contains simple name-value pair of form field */ } else{ //do want file}

i passed through mail service utility, changed name of file right name have right extension, , worked. of course, have encode form multipart form, , have create mime message multipart well. simple after that.

mimebodypart textpart = new mimebodypart(); textpart.setcontent(body, "text/html"); mimebodypart attachfilepart = new mimebodypart(); filedatasource fds = new filedatasource(file); attachfilepart.setdatahandler(new datahandler(fds)); attachfilepart.setfilename(filename); multipart mp = new mimemultipart(); mp.addbodypart(textpart); mp.addbodypart(attachfilepart);

java jsp javamail attachment

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -