1 Reply Latest reply on Apr 26, 2012 3:07 PM by Rogelio Sevilla

    Cannot send email from within Fuse

    Rogelio Sevilla Novice

      Good day everyone,

       

      I'm really struggling with something that I believe it could be a simple fix but I just can't find it. I'm just trying to send an email from within the ESB using a code like this:

       

       

      Session session = Session.getDefaultInstance(props, null);

      MimeMessage message = new MimeMessage(session);

      message.setFrom(new InternetAddress(from));

       

      InternetAddress[] toAddress = new InternetAddress[http://to.size()];

       

      // To get the array of addresses

      for( int i=0; i < to.size(); i++ ) { // changed from a while loop

      toAddress[i] = new InternetAddress(to.get(i));

      }

      System.out.println("sending");

       

      for( int i=0; i < toAddress.length; i++) { // changed from a while loop

      message.addRecipient(Message.RecipientType.TO, toAddress[i]);

      }

       

      message.setSubject("My subject");

      message.setText("Message");

       

       

       

      Transport transport = session.getTransport("smtp");

      transport.connect(host, from, pass);

      transport.sendMessage(message, message.getAllRecipients());

      transport.close();

       

       

       

       

      The code works perfectly well outside the ESB, but within it, I'm getting this exception:

       

       

       

       

      org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to intialize bean emailExample

      at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:638)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:724)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:640)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:331)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:227)10:org.apache.aries.blueprint:0.3.1

      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441):1.6.0_26

      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303):1.6.0_26

      at java.util.concurrent.FutureTask.run(FutureTask.java:138):1.6.0_26

      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98):1.6.0_26

      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206):1.6.0_26

      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886):1.6.0_26

      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908):1.6.0_26

      at java.lang.Thread.run(Thread.java:662):1.6.0_26

      Caused by: javax.mail.MessagingException: IOException while sending message;

      nested exception is:

      javax.activation.UnsupportedDataTypeException: text/plain; charset=us-ascii

      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:930)

      at com.flytecomm.email_example.App.send(App.java:104)

      at com.flytecomm.email_example.App.main(App.java:24)

      at com.flytecomm.email_example.App.init(App.java:29)

      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):1.6.0_26

      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39):1.6.0_26

      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25):1.6.0_26

      at java.lang.reflect.Method.invoke(Method.java:597):1.6.0_26

      at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:226)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:824)10:org.apache.aries.blueprint:0.3.1

      at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:636)10:org.apache.aries.blueprint:0.3.1

      ... 15 more

      Caused by: javax.activation.UnsupportedDataTypeException: text/plain; charset=us-ascii

      at javax.activation.DataHandler.writeTo(DataHandler.java:75):1.6.0_26

      at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1383)120:javax.mail:1.4.3

      at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1743)120:javax.mail:1.4.3

      at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:888)

      ... 25 more

       

       

      Am I missing something??

       

      Thanks a lot in advance for your time.