Hallo all

I am running a Java servlet on a Linux box. All the servlet needs to do
is send an HTML email with an image embedded to a given address. But I
am getting the following error while sending the email:

 

java.lang.ClassCastException: gnu.mail.handler.MultipartRelated

      at
javax.activation.MailcapCommandMap.createDataContentHandler(MailcapComma
ndMap.java:496)

      at
javax.activation.DataHandler.getDataContentHandler(DataHandler.java:568)

      at javax.activation.DataHandler.getContent(DataHandler.java:501)

      at
javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1020)

      at
javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1841)

      at
javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1822)

      at javax.mail.Transport.send(Transport.java:80)

      at
com.o8mobile.handlers.MessageHandler.sendEmail(MessageHandler.java:264)

      at
com.o8mobile.handlers.MessageHandler.sendUserRegisterMessages(MessageHan
dler.java:79)

      at
com.o8mobile.handlers.HomeHandler.userRegister(HomeHandler.java:84)

      at org.apache.jsp.register_jsp._jspService(register_jsp.java:111)

      at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

      at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
va:332)

      at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

      at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

      at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:252)

      at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:173)

      at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:213)

      at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:178)

      at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:126)

      at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:105)

      at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:107)

      at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:1
48)

      at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:86
9)

      at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.proc
essConnection(Http11BaseProtocol.java:664)

      at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint
.java:527)

      at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollow
erWorkerThread.java:80)

      at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
.java:684)

      at java.lang.Thread.run(Thread.java:595)

 

I would like to know if anybody has any idea why this is happening. I am
using the standard java mail api and here is the code I use to send the
email.

 

      // create some properties and get the default Session

      javax.mail.Session session =
javax.mail.Session.getDefaultInstance(emailProps, null);

      session.setDebug(true);

      // create a message

      javax.mail.Message msg = new MimeMessage(session);

 

      // set the from and to address

      msg.setFrom(new InternetAddress(msgFromAddr, msgFromName));

      msg.setRecipient(javax.mail.Message.RecipientType.TO, new
InternetAddress(msgTo));

 

      // Setting the Subject and Content Type

      msg.setSubject(subject);

      //msg.setContent(body, "text/html");

      

                // Create your new message part

                BodyPart messageBodyPart = new MimeBodyPart();

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

                  

                // Create a related multi-part to combine the parts

                MimeMultipart multipart = new MimeMultipart("related");

                multipart.addBodyPart(messageBodyPart);

            

                // Create part for the image

                messageBodyPart = new MimeBodyPart();

            

                // Fetch the image and associate to part

                DataSource fds = new
FileDataSource("/usr/share/tomcat5/image.jpg ");

                messageBodyPart.setDataHandler(new DataHandler(fds));

                messageBodyPart.setHeader("Content-ID","<[EMAIL PROTECTED]>");

                // Add part to multi-part

                multipart.addBodyPart(messageBodyPart);

                // Create 2nd part for the image

                messageBodyPart = new MimeBodyPart();       

                // Fetch the image and associate to part

                DataSource fds2 = new
FileDataSource("/usr/share/tomcat5/image.jpg");

                messageBodyPart.setDataHandler(new DataHandler(fds2));

                messageBodyPart.setHeader("Content-ID","<youyouyou>");

                // Add part to multi-part

                multipart.addBodyPart(messageBodyPart);           

                // Associate multi-part with message

                msg.setContent(multipart);

                // Send message

                Transport.send(msg);

 

Any help would be appreciated. I am all out of ideas. 

 

Thanks

Johan


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 269.2.0/756 - Release Date: 4/10/2007
10:44 PM
 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---

Reply via email to