7 Replies Latest reply on Feb 7, 2013 1:02 AM by Alexander Durnev

    Send email with attachment

    Alex Mak Newbie

      Hello,

       

      I am trying to follow the example here to send an email with an attachment with Fuse.

      There is a "HELLO.TXT" in the fuse directory.

       

       

      http://camel.apache.org/mail.html

      -


       

      import javax.activation.DataHandler;

      import javax.activation.FileDataSource;

       

      import org.apache.camel.CamelContext;

      import org.apache.camel.Endpoint;

      import org.apache.camel.Exchange;

      import org.apache.camel.Message;

      import org.apache.camel.Processor;

      import org.apache.camel.Producer;

       

      public class sendEmail implements Processor {

          public void process(Exchange exchange) throws Exception {

                

               CamelContext context = exchange.getContext();

               Endpoint endpoint = context.getEndpoint("...");  // my smtp connection string here

       

               Message in = exchange.getIn();

               in.setBody("Hello World");

       

               in.addAttachment("HELLO.TXT", new DataHandler(new FileDataSource("HELLO.TXT")));

       

               Producer producer = endpoint.createProducer();

               producer.start();

               producer.process(exchange);

                       

          }

      }

       

       

      I can send the email fine (with my own smtp server), but attachment fails with the following runtime error in the log:

       

       

       

      nested exception is:

              javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

              boundary="----=_Part_0_1855735248.1342812983558"]

      org.apache.camel.RuntimeCamelException: javax.mail.MessagingException: IOException while sending message;

      ...

       

       

      What does DCH mean? What does this exception mean?

      Is there a work around?

       

      Thanks,

      Alex

        • 1. Re: Send email with attachment
          Claus Ibsen Master

          What version of Fuse do you use? And what product, eg Fuse ESB I would assume. Or Fuse ESB Enterprise.

          • 2. Re: Send email with attachment
            Alex Mak Newbie

            I am using Fuse ESB (7.0.0.fuse-061)

            • 3. Re: Send email with attachment
              Claus Ibsen Master

              I think this has been fixed for the upcoming 7.0.1 release.

               

              As a fix on your 7.0.0 release you can try to modify the etc/jre.properties file. And comment out the javax.activation package, eg

              #javax.activation;version="1.1", \
              

               

              And then delete the data directory. And restart the ESB.

              • 4. Re: Send email with attachment
                Alex Mak Newbie

                The solution works!

                 

                However after I deleted the data folder and modified the properties file, fuseesb would not restart, fuseesb.bat would hang with messages like these:

                 

                ERROR: Bundle org.apache.karaf.diagnostic.command Error starting mvn:org.ap

                ache.karaf.diagnostic/org.apache.karaf.diagnostic.command/2.2.5.fuse-7-061 (org.

                osgi.framework.BundleException: Unresolved constraint in bundle org.apache.karaf

                .diagnostic.command : Unable to resolve 37.0: missing requirement osg

                i.wiring.package; (&(osgi.wiring.package=org.apache.felix.gogo.commands)(version

                >=0.10.0)(!(version>=1.0.0))) [caused by: Unable to resolve 19.0: missing requir

                ement osgi.wiring.package; (osgi.wiring.package=javax.security.auth)])

                org.osgi.framework.BundleException: Unresolved constraint in bundle org.apache.k

                araf.diagnostic.command : Unable to resolve 37.0: missing requirement

                osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.gogo.commands)(ver

                sion>=0.10.0)(!(version>=1.0.0))) [caused by: Unable to resolve 19.0: missing re

                quirement osgi.wiring.package; (osgi.wiring.package=javax.security.auth)]

                ...

                 

                 

                I had to reinstall the entire Fuse system, redo the two steps, and email attachment works.

                • 5. Re: Send email with attachment
                  Alexander Durnev Newbie

                  Has the issue been fixed? I have the same error on Fuse ESB 7.1.0.

                  • 6. Re: Send email with attachment
                    Alexander Durnev Newbie

                    I've tried the suggested solution, but I received the following error:

                     

                    -


                    Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.apache.camel.Message.addAttachment(Ljava/lang/String;Ljavax/activation/DataHandler;)V" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, MyBean, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for resolved class, org/apache/camel/Message, have different Class objects for the type javax/activation/DataHandler used in the signature

                    -


                     

                    By the way, my bundle has worked perfectly on Fuse ESB/ServiceMix 4.4.1.

                    • 7. Re: Send email with attachment
                      Alexander Durnev Newbie

                      I've added javax.activation;version=1.1 to Import-Package and now it finally works.