You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Nikos <be...@gmail.com> on 2014/06/09 16:41:02 UTC

Cannot send email with attachment

Hi,

I use SMX 5.0.My camel route works OK when I send simple mail to smtp but it
fails when I change it to support attachments. The sending of an email with
a txt attachment fails with the following error:

---------------------------------------------------------------------------------------------------------------------------------------
javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: plain/text
        at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1177)[93:javax.mail:1.4.5]
        at
org.apache.camel.component.mail.DefaultJavaMailSender.send(DefaultJavaMailSender.java:124)[179:org.apache.camel.camel-mail:2.12.3]
        at
org.apache.camel.component.mail.MailProducer.process(MailProducer.java:56)[179:org.apache.camel.camel-mail:2.12.3]
        at
org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[63:org.apache.came
l.camel-core:2.12.3]
        at
org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:132)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:307)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:127)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:401)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:201)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:165)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)[63:org.apache.camel.camel-core:2.12.3]
        at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)[63:org.apache.camel.camel-core:2.12.3]
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_17]
        at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)[:1.7.0_17]
        at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)[:1.7.0_17]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)[:1.7.0_17]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.7.0_17]
        at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_17]
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_17]
        at java.lang.Thread.run(Thread.java:722)[:1.7.0_17]
*Caused by: javax.activation.UnsupportedDataTypeException: plain/text
        at
javax.activation.DataHandler.writeTo(DataHandler.java:75)*[51:org.apache.servicemix.specs.activation-api-1.1:2.2.0]
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)[58:javax.mail:1.4.4]
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865)[58:javax.mail:1.4.4]
        at
javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462)[58:javax.mail:1.4.4]
        at
com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103)[93:javax.mail:1.4.5]
        at
javax.activation.DataHandler.writeTo(DataHandler.java:77)[51:org.apache.servicemix.specs.activation-api-1.1:2.2.0]
        at
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)[58:javax.mail:1.4.4]
        at
javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)[58:javax.mail:1.4.4]
        at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121)[93:javax.mail:1.4.5]



--
View this message in context: http://servicemix.396122.n5.nabble.com/Cannot-send-email-with-attachment-tp5720765.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Cannot send email with attachment

Posted by Nikos <be...@gmail.com>.
You are correct. I have slightly updated the code to attach a dynamic file.
The follow code works OK.

from(file://...)...
public void process(Exchange exchange) throws Exception {					
	Message in = exchange.getIn();
	String file = in.getBody(String.class);
	String fileId = in.getHeader("CamelFileName",String.class);
	in.addAttachment(fileId, new DataHandler(file,"text/plain"));
}
.to(file://...)



--
View this message in context: http://servicemix.396122.n5.nabble.com/Cannot-send-email-with-attachment-tp5720765p5720772.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Cannot send email with attachment

Posted by Freeman Fang <fr...@gmail.com>.
Hi,

Your code isn't correct,  it should be "text/plain" but not "plain/text" per the mail cap. 
-------------
Freeman(Yue) Fang

Red Hat, Inc. 
FuseSource is now part of Red Hat



On 2014-6-9, at 下午10:54, Nikos wrote:

> Hi JB,
> 
> Yes. Please find below the route.
> 
> from("file:{{foldername}}?recursive=true&readLock=changed")			
> .process(new Processor() {
> 		@Override
> 		public void process(Exchange exchange) throws Exception {
> 			File file = new File("/home/user1/testfile.txt");
> 			exchange.getIn().addAttachment("testfile.txt",
> newDataHandler(file,"plain/text"));
> 		}
> 		})
> 	.log("Attachment added.")
> 	.to(smtp://...)
> 
> 
> 
> 
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Cannot-send-email-with-attachment-tp5720765p5720768.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Cannot send email with attachment

Posted by Nikos <be...@gmail.com>.
Hi JB,

Yes. Please find below the route.

from("file:{{foldername}}?recursive=true&readLock=changed")			
.process(new Processor() {
		@Override
		public void process(Exchange exchange) throws Exception {
			File file = new File("/home/user1/testfile.txt");
			exchange.getIn().addAttachment("testfile.txt",
newDataHandler(file,"plain/text"));
		}
		})
	.log("Attachment added.")
	.to(smtp://...)




--
View this message in context: http://servicemix.396122.n5.nabble.com/Cannot-send-email-with-attachment-tp5720765p5720768.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Re: Cannot send email with attachment

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Nikos,

Did you specify a data handler on the attachment when you add to the in 
message ?

in.addAttachment("logo.jpeg", new DataHandler(new 
FileDataSource("src/test/data/logo.jpeg")));

Regards
JB

On 06/09/2014 04:41 PM, Nikos wrote:
> Hi,
>
> I use SMX 5.0.My camel route works OK when I send simple mail to smtp but it
> fails when I change it to support attachments. The sending of an email with
> a txt attachment fails with the following error:
>
> ---------------------------------------------------------------------------------------------------------------------------------------
> javax.mail.MessagingException: IOException while sending message;
>    nested exception is:
>          javax.activation.UnsupportedDataTypeException: plain/text
>          at
> com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1177)[93:javax.mail:1.4.5]
>          at
> org.apache.camel.component.mail.DefaultJavaMailSender.send(DefaultJavaMailSender.java:124)[179:org.apache.camel.camel-mail:2.12.3]
>          at
> org.apache.camel.component.mail.MailProducer.process(MailProducer.java:56)[179:org.apache.camel.camel-mail:2.12.3]
>          at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[63:org.apache.came
> l.camel-core:2.12.3]
>          at
> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:132)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:307)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:127)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:401)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:201)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:165)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)[63:org.apache.camel.camel-core:2.12.3]
>          at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)[63:org.apache.camel.camel-core:2.12.3]
>          at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)[:1.7.0_17]
>          at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)[:1.7.0_17]
>          at
> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)[:1.7.0_17]
>          at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)[:1.7.0_17]
>          at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.7.0_17]
>          at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_17]
>          at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_17]
>          at java.lang.Thread.run(Thread.java:722)[:1.7.0_17]
> *Caused by: javax.activation.UnsupportedDataTypeException: plain/text
>          at
> javax.activation.DataHandler.writeTo(DataHandler.java:75)*[51:org.apache.servicemix.specs.activation-api-1.1:2.2.0]
>          at
> javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)[58:javax.mail:1.4.4]
>          at
> javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:865)[58:javax.mail:1.4.4]
>          at
> javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:462)[58:javax.mail:1.4.4]
>          at
> com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103)[93:javax.mail:1.4.5]
>          at
> javax.activation.DataHandler.writeTo(DataHandler.java:77)[51:org.apache.servicemix.specs.activation-api-1.1:2.2.0]
>          at
> javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)[58:javax.mail:1.4.4]
>          at
> javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)[58:javax.mail:1.4.4]
>          at
> com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1121)[93:javax.mail:1.4.5]
>
>
>
> --
> View this message in context: http://servicemix.396122.n5.nabble.com/Cannot-send-email-with-attachment-tp5720765.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com