Hi All,
I used the sample code from commons-email user-guide page on apache site and
wrote a simple java class to send email with mail attachments. I made this java class
as a servicemix POJO component which will accept a xml message.
I prepared a small xml template to hold the mailing details like below:
<emessage>
<email>
<mail-host>mail.mycomp.com</mail-host>
<to>[EMAIL PROTECTED], [EMAIL PROTECTED]</to>
<from>[EMAIL PROTECTED]</from>
<cc>[EMAIL PROTECTED], [EMAIL PROTECTED]</cc>
<bcc>[EMAIL PROTECTED], [EMAIL PROTECTED]</bcc>
<subject>This is subject test mail.</subject>
<body> This is the body content of the test mail.</body>
<attachments>C:/tmp/test/att01.pdf|C:/tmp/test/att02.pdf </attachments>
</email>
</emessage>
when I tried to run this code using the "ServiceMix2.1-SNAPSHOT" the problem was,
it was not able to attach the files to the email complaining an error
- org.apache.commons.mail.EmailException: Cannot attach file "C:/tmp/test/att01.pdf".
I thought this would be a problem with my java class or the file is not existing,
so I cheked the existence of files and tried running it from within a normal java code
and it was sending the mail correctly. I tried changing the code in
different ways ,but the error still persisted when I tried invoking the component.
I changed my plan and tried running the same code using "ServiceMix-3.0-SNAPSHOT".
This time everything went on well and the mail was sent successfully. But when I observed
the mail that was recieved, it looked like some junk. On closely seeing at the content I found
the attached pdf files are being shown as text which generally happens due to setting incorrect
content-type or mime-type.Again I tried running the emailing code from a normal java program
and saw the output in recieved mails and is fine showing the pdfs as attachments.
Can somebody give me a idea of what is going wrong when I am trying to run the code as
a component which is running smoothly as a normal java program.
Here I am attaching all the esb-script, log message tracing when ran with 2.0 and 3.0 SNAPSHOTS
and the content of the recieved mail(junk text) for the reference.
Thanks in advance,
Pavan Kumar
</emessage>
when I tried to run this code using the "ServiceMix2.1-SNAPSHOT" the problem was,
it was not able to attach the files to the email complaining an error
- org.apache.commons.mail.EmailException: Cannot attach file "C:/tmp/test/att01.pdf".
I thought this would be a problem with my java class or the file is not existing,
so I cheked the existence of files and tried running it from within a normal java code
and it was sending the mail correctly. I tried changing the code in
different ways ,but the error still persisted when I tried invoking the component.
I changed my plan and tried running the same code using "ServiceMix-3.0-SNAPSHOT".
This time everything went on well and the mail was sent successfully. But when I observed
the mail that was recieved, it looked like some junk. On closely seeing at the content I found
the attached pdf files are being shown as text which generally happens due to setting incorrect
content-type or mime-type.Again I tried running the emailing code from a normal java program
and saw the output in recieved mails and is fine showing the pdfs as attachments.
Can somebody give me a idea of what is going wrong when I am trying to run the code as
a component which is running smoothly as a normal java program.
Here I am attaching all the esb-script, log message tracing when ran with 2.0 and 3.0 SNAPSHOTS
and the content of the recieved mail(junk text) for the reference.
Thanks in advance,
Pavan Kumar
<========================================ESB SCRIPT==================================================>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xbean.org/schemas/spring/1.0" xmlns:spring="http://xbean.org/schemas/spring/1.0" xmlns:sm="http://servicemix.apache.org/config/1.0" xmlns:foo="http://mycomp.com/test/"> <!-- the JBI container * The attribute flowName="st" makes the esb config to use single thread model. --> <sm:container id="jbi" useMBeanServer="true" createMBeanServer="true" dumpStats="true" statsInterval="10" flowName="st"> <sm:activationSpecs> <sm:activationSpec componentName="tracer" service="foo:tracer"> <sm:component> <bean xmlns="http://xbean.org/schemas/spring/1.0" class="org.apache.servicemix.components.util.StreamWriterComponent" /> </sm:component> </sm:activationSpec> <sm:activationSpec componentName="filePoller" service="foo:filePoller" destinationService="foo:emailer"> <sm:component> <bean xmlns="http://xbean.org/schemas/spring/1.0" class="org.apache.servicemix.components.file.FilePoller"> <property name="file" value="inbox"/> <property name="period" value="20000"/> <property name="deleteFile" value="true"/> <property name="workManager" ref="workManager"/> </bean> </sm:component> </sm:activationSpec> <sm:activationSpec componentName="emailer" service="foo:emailer" destinationService="foo:tracer"> <sm:component> <bean xmlns="http://xbean.org/schemas/spring/1.0" class="com.mycomp.esb.Emailer"> <property name="mailHost"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/mail-host" /> </bean> </property> <property name="to"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/to" /> </bean> </property> <property name="from"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/from" /> </bean> </property> <property name="cc"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/cc" /> </bean> </property> <property name="bcc"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/bcc" /> </bean> </property> <property name="subject"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/subject" /> </bean> </property> <property name="body"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/body" /> </bean> </property> <property name="attachments"> <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression"> <constructor-arg value="/emessage/email/attachments" /> </bean> </property> </bean> </sm:component> </sm:activationSpec> </sm:activationSpecs> </sm:container> <!-- the work manager (thread pool) for this container --> <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean"> <property name="threadPoolSize" value="1" /> </bean> </beans> <========================== LOG OF STACK TRACE WHEN RAN WITH ServiceMix2.1-SNAPSHOT ======================> DEBUG - FilePoller.pollFile(178) | Scheduling file inbox\email01.xml for processing DEBUG - FilePoller.processFileAndDelete(194) | Processing file inbox\email01.xml INFO - DeliveryChannelImpl.createExchangeFactory(165) | default destination serviceName for filePoller = {http://mycomp.com/test/}emailer DEBUG - Broker.resolveAddress(373) | Routing exchange [EMAIL PROTECTED] to: ServiceEndpoint[service={http://mycomp.com/test/}emailer,endpoint=emailer] DEBUG - AbstractFlow.send(117) | Called Flow send DEBUG - AbstractFlow.doRouting(175) | Called Flow doRouting INFO - Emailer.process(235) | [mailhost,to,from,cc,bcc,sub,body,att] - [mail.mycomp.com,[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],This is test mail ., This is the body content of the test mail .,C:/tmp/test/att01.pdf|C:/tmp/test/att02.pdf ] INFO - Emailer.sendMailwithAttachments(254) | ====================Log Messsages Email with Attachments ============================ INFO - Emailer.sendMailwithAttachments(256) | [mailhost,to,from,cc,bcc,sub,body,att] - [mail.mycomp.com<--->[EMAIL PROTECTED],[EMAIL PROTECTED]<--->[EMAIL PROTECTED]<--->[EMAIL PROTECTED],[EMAIL PROTECTED]<--->[EMAIL PROTECTED],[EMAIL PROTECTED]<--->This is test mail.<---> This is the body content of the test mail.<--->C:/tmp/test/ att01.pdf|C:/tmp/test/att02.pdf ] INFO - Emailer.sendMailwithAttachments(272) | Attachment name -> att01.pdf INFO - Emailer.sendMailwithAttachments(272) | Attachment name -> att02.pdf INFO - Emailer.sendMailwithAttachments(280) | Message part for email created. INFO - Emailer.sendMailwithAttachments(287) | 'To-list' for Email has been set. INFO - Emailer.sendMailwithAttachments(290) | 'From' for email has been set. INFO - Emailer.sendMailwithAttachments(297) | cc list for email has been set. INFO - Emailer.sendMailwithAttachments(304) | bcc list for email has been set. INFO - Emailer.sendMailwithAttachments(307) | subject for email has been set. INFO - Emailer.sendMailwithAttachments(309) | message-body for email has been set. ERROR - Emailer.sendMailwithAttachments(325) | There is problem in sending the mail in sendMailwithAttachments(). ERROR - Emailer.sendMailwithAttachments(326) | org.apache.commons.mail.EmailException: Cannot attach file "C:/tmp/test/att01.pdf" Cannot attach file "C:/tmp/test/att01.pdf" org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:301) com.mycomp.esb.Emailer.sendMailwithAttachments(Emailer.java:315) com.mycomp.esb.Emailer.process(Emailer.java:236) org.servicemix.components.util.OutBinding.onMessageExchange(OutBinding.java:51) org.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:590) org.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:182) org.servicemix.jbi.nmr.flow.st.STFlow.doSend(STFlow.java:45) org.servicemix.jbi.nmr.flow.AbstractFlow.send(AbstractFlow.java:124) org.servicemix.jbi.nmr.Broker.sendExchangePacket(Broker.java:289) org.servicemix.jbi.container.JBIContainer.sendExchange(JBIContainer.java:590) org.servicemix.jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java:349) org.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:423) org.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:400) org.servicemix.components.file.FilePoller.processFile(FilePoller.java:220) org.servicemix.components.file.FilePoller.processFileAndDelete(FilePoller.java:197) org.servicemix.components.file.FilePoller$1.run(FilePoller.java:182) org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291) EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Thread.java:595) java.lang.UnsupportedOperationException: Method not yet implemented Method not yet implemented javax.mail.internet.MimeBodyPart.setFileName(MimeBodyPart.java:167) org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:432) org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:292) com.mycomp.esb.Emailer.sendMailwithAttachments(Emailer.java:315) com.mycomp.esb.Emailer.process(Emailer.java:236) org.servicemix.components.util.OutBinding.onMessageExchange(OutBinding.java:51) org.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:590) org.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:182) org.servicemix.jbi.nmr.flow.st.STFlow.doSend(STFlow.java:45) org.servicemix.jbi.nmr.flow.AbstractFlow.send(AbstractFlow.java:124) org.servicemix.jbi.nmr.Broker.sendExchangePacket(Broker.java:289) org.servicemix.jbi.container.JBIContainer.sendExchange(JBIContainer.java:590) org.servicemix.jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java:349) org.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:423) org.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:400) org.servicemix.components.file.FilePoller.processFile(FilePoller.java:220) org.servicemix.components.file.FilePoller.processFileAndDelete(FilePoller.java:197) org.servicemix.components.file.FilePoller$1.run(FilePoller.java:182) org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291) EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Thread.java:595) INFO - Emailer.sendMailwithAttachments(329) | =========================================================================================== ERROR - PojoSupport.fail(254) | Error processing exchange java.lang.Exception: Problem occured while sending the email.Contact your admin. at com.mycomp.esb.Emailer.process(Emailer.java:242) at org.servicemix.components.util.OutBinding.onMessageExchange(OutBinding.java:51) at org.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:590) at org.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:182) at org.servicemix.jbi.nmr.flow.st.STFlow.doSend(STFlow.java:45) at org.servicemix.jbi.nmr.flow.AbstractFlow.send(AbstractFlow.java:124) at org.servicemix.jbi.nmr.Broker.sendExchangePacket(Broker.java:289) at org.servicemix.jbi.container.JBIContainer.sendExchange(JBIContainer.java:590) at org.servicemix.jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java:349) at org.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:423) at org.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:400) at org.servicemix.components.file.FilePoller.processFile(FilePoller.java:220) at org.servicemix.components.file.FilePoller.processFileAndDelete(FilePoller.java:197) at org.servicemix.components.file.FilePoller$1.run(FilePoller.java:182) at org.apache.geronimo.connector.work.WorkerContext.run(WorkerContext.java:291) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Thread.java:595) DEBUG - AbstractFlow.send(117) | Called Flow send DEBUG - AbstractFlow.doRouting(175) | Called Flow doRouting <=====================================LOG OF STACK TRACE WHEN RAN WITH ServiceMix-3.0-SNAPSHOT========================> DEBUG - FilePoller.pollFileOrDirectory(151) | Polling directory inbox DEBUG - FilePoller.pollFile(165) | Scheduling file inbox\email01.xml for processing DEBUG - FilePoller.processFileAndDelete(181) | Processing file inbox\email01.xml DEBUG - Broker.resolveAddress(388) | Routing exchange [EMAIL PROTECTED] to: ServiceEndpoint[service={http://mycomp.com/test/}emailer,endpoint=emailer] DEBUG - AbstractFlow.send(116) | Called Flow send DEBUG - AbstractFlow.doRouting(165) | Called Flow doRouting INFO - Emailer.process(235) | [mailhost,to,from,cc,bcc,sub,body,att] - [mail.mycomp.com,[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED],This is test mail ., This is the body content of the test mail .,C:/tmp/test/o2791450.pdf|C:/tmp/test/o2791453.pdf ] INFO - Emailer.sendMailwithAttachments(254) | ====================Log Messsages Email with Attachments ============================ INFO - Emailer.sendMailwithAttachments(256) | [mailhost,to,from,cc,bcc,sub,body,att] - [mail.mycomp.com<--->[EMAIL PROTECTED],[EMAIL PROTECTED]<--->[EMAIL PROTECTED]<--->[EMAIL PROTECTED],[EMAIL PROTECTED]<--->[EMAIL PROTECTED],[EMAIL PROTECTED]<--->This is test mail .<---> This is the body content of the test mail .<--->C:/tmp/test/ o2791450.pdf|C:/tmp/test/o2791453.pdf ] INFO - Emailer.sendMailwithAttachments(272) | Attachment name -> o2791450.pdf INFO - Emailer.sendMailwithAttachments(272) | Attachment name -> o2791453.pdf INFO - Emailer.sendMailwithAttachments(280) | Message part for email created. INFO - Emailer.sendMailwithAttachments(287) | 'To-list' for Email has been set. INFO - Emailer.sendMailwithAttachments(290) | 'From' for email has been set. INFO - Emailer.sendMailwithAttachments(297) | cc list for email has been set. INFO - Emailer.sendMailwithAttachments(304) | bcc list for email has been set. INFO - Emailer.sendMailwithAttachments(307) | subject for email has been set. INFO - Emailer.sendMailwithAttachments(309) | message-body for email has been set. 1 name = META-INF/mime.types attachement added to mail. DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\install for new or modified archives DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\deploy for new or modified archives DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\install for new or modified archives DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\deploy for new or modified archives DEBUG - FilePoller.pollFileOrDirectory(151) | Polling directory inbox DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\install for new or modified archives DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\deploy for new or modified archives INFO - Emailer.sendMailwithAttachments(321) | email has been sent successfully. INFO - Emailer.sendMailwithAttachments(329) | =========================================================================================== DEBUG - AbstractFlow.send(116) | Called Flow send DEBUG - AbstractFlow.doRouting(165) | Called Flow doRouting DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\install for new or modified archives DEBUG - AutoDeploymentService.monitorDirectory(483) | Monitoring directory C:\Installations\JavaEE\AppServers\ServiceMix\servicemix-3.0-SNAPSHOT\ATeOP\rootDir\deploy for new or modified archives DEBUG - FilePoller.pollFileOrDirectory(151) | Polling directory inbox <=========================================== JUNK CONTENT RECIVED WHEN USED ServiceMix-3.0-SNAPSHOT ===================================================> ------=_Part_0.1144073440659 This is the body content of the test mail . ------=_Part_0.1144073440659 content-disposition:attachment; filename=o2791450.pdf content-description:mail attachment %PDF-1.4 %âãÏÓ 2 0 obj <</Filter/FlateDecode/Length 642>>stream x¥VÛrÚ0}ç+ö´J«í¼Ñ:Ãebg:[EMAIL PROTECTED](ÛvâÐZÚ³{ttdÑáAò«ó1ép`îÃ#:ä®óáÂÍÜãe§{|;Z ÂÝ.üçPpUæÉ nÒÆÔ~ÞSLéaaéi`¶\æñv³)rS÷`\.NÛðªEpYh¦àkj)ëû¼(|2ec,\ViÖWÔÇ1åCUÿË`ÚgøÉ5©%ẕÝÀM×Ä] ëÞ`7'ûÖç1yô3ßæ¯DH"áAç[CëÈ}á=ØSHµ?©57]äÚ ¡èKÆÃI?Qô=ûÉ (`cêkHËÒ»j[65T%4«Ü}ÛÌ©*µÌ5uí´pW1dUQ¤ÖÏÿ±]_Î&ãxx~ö0W§ÎCébõ¸$5Ô &©AEºJ²KdÈÉ.]òìd< »äºý <Ý߯0éüÕoåá endstream endobj 4 0 obj<</Type/Page/Contents 2 0 R/Parent 3 0 R/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 1 0 R>>>>/MediaBox[0 0 612 792]>> endobj 1 0 obj<</Type/Font/BaseFont/Courier/Subtype/Type1/Encoding/WinAnsiEncoding>> endobj 3 0 obj<</Count 1/Type/Pages/Kids[4 0 R]>> endobj 5 0 obj<</Type/Catalog/Pages 3 0 R>> endobj 6 0 obj<</CreationDate(D:20060317215521+05'30')/Producer(iText1.1 by lowagie.com \(based on itext-paulo-142\))/ModDate(D:20060317215521+05'30')>> endobj xref 0 7 0000000000 65535 f 0000000880 00000 n 0000000015 00000 n 0000000965 00000 n 0000000724 00000 n 0000001015 00000 n 0000001059 00000 n trailer <</ID [<c0442af2fe3f7656f46bba0efb7d408a><c0442af2fe3f7656f46bba0efb7d408a>]/Root 5 0 R/Size 7/Info 6 0 R>> startxref 1212 %%EOF ------=_Part_0.1144073440659 content-disposition:attachment; filename="o2791453.pdf " content-description:mail attachment %PDF-1.4 %âãÏÓ 2 0 obj <</Filter/FlateDecode/Length 642>>stream x¥VÛrÚ0}ç+ö´J«í¼Ñ:Ãebg:[EMAIL PROTECTED](ÛvâÐZÚ³{ttdÑáAò«ó1ép`îÃ#:ä®óáÂÍÜãe§{|;Z ÂÝ.üçPpUæÉ nÒÆÔ~ÞSLéaaéi`¶\æñv³)rS÷`\.NÛðªEpYh¦àkj)ëû¼(|2ec,\ViÖWÔÇ1åCUÿË`ÚgøÉ5©%ẕÝÀM×Ä] ëÞ`7'ûÖç1yô3ßæ¯DH"áAç[CëÈ}á=ØSHµ?©57]äÚ ¡èKÆÃI?Qô=ûÉ (`cêkHËÒ»j[65T%4«Ü}ÛÌ©*µÌ5uí´pW1dUQ¤ÖÏÿ±]_Î&ãxx~ö0W§ÎCébõ¸$5Ô &©AEºJ²KdÈÉ.]òìd< »äºý <Ý߯0éüÕoåá endstream endobj 4 0 obj<</Type/Page/Contents 2 0 R/Parent 3 0 R/Resources<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]/Font<</F1 1 0 R>>>>/MediaBox[0 0 612 792]>> endobj 1 0 obj<</Type/Font/BaseFont/Courier/Subtype/Type1/Encoding/WinAnsiEncoding>> endobj 3 0 obj<</Count 1/Type/Pages/Kids[4 0 R]>> endobj 5 0 obj<</Type/Catalog/Pages 3 0 R>> endobj 6 0 obj<</CreationDate(D:20060317221145+05'30')/Producer(iText1.1 by lowagie.com \(based on itext-paulo-142\))/ModDate(D:20060317221145+05'30')>> endobj xref 0 7 0000000000 65535 f 0000000880 00000 n 0000000015 00000 n 0000000965 00000 n 0000000724 00000 n 0000001015 00000 n 0000001059 00000 n trailer <</ID [<e37d8ca05c4626b86470e062e25ba884><e37d8ca05c4626b86470e062e25ba884>]/Root 5 0 R/Size 7/Info 6 0 R>> startxref 1212 %%EOF ------=_Part_0.1144073440659--
