java - javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed -
i'm trying send multiple emails within loop employees of sample database. after records retrieved database, loops begins sending emails text , attachment each of them. problem sends 1 recipient before throwing error in title. believe error between multipart = new mimemultipart() , message.setcontent(multipart) because if didn't include part , put message.settext("hello"), multiple emails send. missing?
file folder = new file(directory); file[] existingfiles = folder.listfiles(); for(int = 0; < existingfiles.length; a++) { existingfiles[a].delete(); } multipartrequest mr = new multipartrequest(request, directory, 52428800); string[] newfiles = folder.list(); string query = "select emp_first_name, emp_last_name, emp_email_address employee emp_company_id = ?"; preparedstatement pstmt = con.preparestatement(query); properties props = new properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); session session = session.getinstance(props, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication("email@gmail.com", "password"); } }); message message; mimebodypart messagebodypart; multipart multipart; datasource source; datahandler handler; file file; for(int = 0; < newfiles.length; i++) { pstmt.setstring(1, newfiles[i]); rst = pstmt.executequery(); pstmt.clearparameters(); if(rst.next()) { message = new mimemessage(session); message.setfrom(new internetaddress("email@gmail.com")); message.setrecipients(message.recipienttype.to, internetaddress.parse(rst.getstring(3))); message.setsubject("a subject"); multipart = new mimemultipart(); messagebodypart = new mimebodypart(); messagebodypart.settext("text"); multipart.addbodypart(messagebodypart); messagebodypart = new mimebodypart(); file = new file(directory, newfiles[i]); source = new filedatasource(file); handler = new datahandler(source); messagebodypart.setdatahandler(handler); messagebodypart.setfilename(rst.getstring(1) + " " + rst.getstring(2) + ".pdf"); multipart.addbodypart(messagebodypart); message.setcontent(multipart); transport.send(message); } else { return false; } //thread.sleep(3000); } pstmt.closeoncompletion(); rst.close();
severe: javax.mail.messagingexception: ioexception while sending message; >nested exception is: javax.activation.unsupporteddatatypeexception: no object dch mime type >multipart/mixed; boundary="----=_part_2_2127721582.1505308952342" @ com.sun.mail.smtp.smtptransport.sendmessage(smtptransport.java:1245) @ javax.mail.transport.send0(transport.java:254) @ javax.mail.transport.send(transport.java:124) @ beans.employee.uploadanddeliverpayslips(employee.java:98) @ >org.apache.jsp.jsp.processuploadpayslips_jsp.jspservice(processuploadpayslips>jsp.java:58) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:111) @ javax.servlet.http.httpservlet.service(httpservlet.java:790) @ >org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:411) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:473) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:377) @ javax.servlet.http.httpservlet.service(httpservlet.java:790) @ >org.apache.catalina.core.standardwrapper.service(standardwrapper.java:1682) @ >org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:>318) @ >org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:>160) @ >org.apache.catalina.core.standardpipeline.doinvoke(standardpipeline.java:734) @ >org.apache.catalina.core.standardpipeline.invoke(standardpipeline.java:673) @ com.sun.enterprise.web.webpipeline.invoke(webpipeline.java:99) @ >org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:174) @ >org.apache.catalina.connector.coyoteadapter.doservice(coyoteadapter.java:416) @ >org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:283) @ >com.sun.enterprise.v3.services.impl.containermapper$httphandlercallable.call(co>ntainermapper.java:459) @ >com.sun.enterprise.v3.services.impl.containermapper.service(containermapper.jav>a:167) @ >org.glassfish.grizzly.http.server.httphandler.runservice(httphandler.java:206) @ >org.glassfish.grizzly.http.server.httphandler.dohandle(httphandler.java:180) @ >org.glassfish.grizzly.http.server.httpserverfilter.handleread(httpserverfilter.>java:235) @ >org.glassfish.grizzly.filterchain.executorresolver$9.execute(executorresolver.j>ava:119) @ >org.glassfish.grizzly.filterchain.defaultfilterchain.executefilter(defaultfilte>rchain.java:283) @ >org.glassfish.grizzly.filterchain.defaultfilterchain.executechainpart(defaultfil>terchain.java:200) @ >org.glassfish.grizzly.filterchain.defaultfilterchain.execute(defaultfilterchain>.java:132) @ >org.glassfish.grizzly.filterchain.defaultfilterchain.process(defaultfilterchain>.java:111) @ >org.glassfish.grizzly.processorexecutor.execute(processorexecutor.java:77) @ >org.glassfish.grizzly.nio.transport.tcpniotransport.fireioevent(tcpniotransport>.java:536) @ >org.glassfish.grizzly.strategies.abstractiostrategy.fireioevent(abstractiostrat>egy.java:112) @ >org.glassfish.grizzly.strategies.workerthreadiostrategy.run0(workerthreadiostra>tegy.java:117) @ >org.glassfish.grizzly.strategies.workerthreadiostrategy.access$100(workerthread>iostrategy.java:56) @ >org.glassfish.grizzly.strategies.workerthreadiostrategy$workerthreadrunnable.ru>n(workerthreadiostrategy.java:137) @ >org.glassfish.grizzly.threadpool.abstractthreadpool$worker.dowork(abstractthrea>dpool.java:591) @ >org.glassfish.grizzly.threadpool.abstractthreadpool$worker.run(abstractthreadpo>ol.java:571) @ java.lang.thread.run(thread.java:745) caused by: javax.activation.unsupporteddatatypeexception: no object dch >mime type multipart/mixed; boundary="----=_part_2_2127721582.1505308952342" @ javax.activation.objectdatacontenthandler.writeto(datahandler.java:896) @ javax.activation.datahandler.writeto(datahandler.java:317) @ javax.mail.internet.mimebodypart.writeto(mimebodypart.java:1627) @ javax.mail.internet.mimemessage.writeto(mimemessage.java:1849) @ com.sun.mail.smtp.smtptransport.sendmessage(smtptransport.java:1196) ... 38 more
Comments
Post a Comment