Forum Home » Fuse Distributions » Fuse ESB

Thread: Send email with attachment

 
This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 7 - Last Post: Feb 7, 2013 6:02 AM Last Post By: alexander.durnev
alexcmak

Posts: 7
Registered: 07/05/12
Send email with attachment
Posted: Jul 20, 2012 8:24 PM
 
  Click to reply to this thread Reply
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

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Send email with attachment
Posted: Jul 21, 2012 7:19 AM   in response to: alexcmak in response to: alexcmak
 
  Click to reply to this thread Reply
What version of Fuse do you use? And what product, eg Fuse ESB I would assume. Or Fuse ESB Enterprise.
alexcmak

Posts: 7
Registered: 07/05/12
Re: Send email with attachment
Posted: Jul 21, 2012 12:58 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
I am using Fuse ESB (7.0.0.fuse-061)
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Send email with attachment
Posted: Jul 22, 2012 1:16 PM   in response to: alexcmak in response to: alexcmak
 
  Click to reply to this thread Reply
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.
alexcmak

Posts: 7
Registered: 07/05/12
Re: Send email with attachment
Posted: Jul 23, 2012 3:48 PM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
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 37 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 37: Unable to resolve 37.0: missing requirement http://37.0 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 http://19.0] osgi.wiring.package; (osgi.wiring.package=javax.security.auth))
org.osgi.framework.BundleException: Unresolved constraint in bundle org.apache.k
araf.diagnostic.command 37: Unable to resolve 37.0: missing requirement http://37.0
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 http://19.0] 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.

alexander.durnev

Posts: 11
Registered: 01/31/13
Re: Send email with attachment
Posted: Feb 6, 2013 1:22 PM   in response to: alexcmak in response to: alexcmak
 
  Click to reply to this thread Reply
Has the issue been fixed? I have the same error on Fuse ESB 7.1.0.
alexander.durnev

Posts: 11
Registered: 01/31/13
Re: Send email with attachment
Posted: Feb 6, 2013 2:03 PM   in response to: alexander.durnev in response to: alexander.durnev
 
  Click to reply to this thread Reply
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.
alexander.durnev

Posts: 11
Registered: 01/31/13
Re: Send email with attachment
Posted: Feb 7, 2013 6:02 AM   in response to: alexander.durnev in response to: alexander.durnev
 
  Click to reply to this thread Reply
I've added javax.activation;version=1.1 to Import-Package and now it finally works.