3 Replies Latest reply on Nov 27, 2009 11:44 AM by Claus Ibsen

    Camel - Mail - Using SMTP to sent  emil

    mat dav Newbie

      Hi ,

       

      I am getting the following exception , when I try to send an email from an ftp folder. The same piece of code works standalone. But when I run as a bundle in Fuse- fuse-esb-4.1.0.2, i get this error.   Any tips appreciated. Thank you

       

      Iam using JavaMail to connect to to read email in the same bundle, and using the session.getInsance() method , that works fine.

       

      Is there any way I can  change the camel mail to call the getInstance Method?

       

      from(ftpUrl).to("smtp://mdav@localhost:8825?password=pass&from=mdav@domain.com&To=mdav@devlinux.domain.ca");

       

       

      Exception in thread "SpringOsgiExtenderThread-78" java.lang.SecurityException: A

      ccess to default session denied

              at javax.mail.Session.getDefaultInstance(Session.java:321)

              at org.apache.camel.component.mail.MailConfiguration.createJavaMailSende

      r(MailConfiguration.java:139)

              at org.apache.camel.component.mail.MailEndpoint.createProducer(MailEndpo

      int.java:55)

              at org.apache.camel.processor.SendProcessor.doStart(SendProcessor.java:9

      3)

              at org.apache.camel.impl.ServiceSupport.start(ServiceSupport.java:53)

              at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:4

      2)

              at org.apache.camel.util.ServiceHelper.startServices(ServiceHelper.java:

      53)

              at org.apache.camel.processor.DelegateProcessor.doStart(DelegateProcesso

      r.java:68)

       

      mdav

       

      Edited by: mdav on Nov 25, 2009 11:50 PM

        • 1. Re: Camel - Mail - Using SMTP to sent  emil
          Claus Ibsen Master

          No you can extend MailConfiguration in your own class and invoke the getInstance method. And then configure your mail configuration on the mail component. Then Camel will use your class instead of its own.

           

          The current code calls:

          Session session = Session.getDefaultInstance(prop, getAuthenticator());
          

           

          But what you want to do is:

          Session session = Session.getInstance(prop, getAuthenticator());
          

           

          I wonder what the difference is between these two methods. Well gotta check the javadoc API for Java Mail

          • 2. Re: Camel - Mail - Using SMTP to sent  emil
            mat dav Newbie

            Thanks for the reply.I will try with this.

             

            Just wanted to share , what I saw in the doc.

             

            It looks like the default session , which may contain credentials is denied if objects are called from two different classloader.

             

            But if  the Authenticator object used to create the session is null, we can get the default session.

             

            Cheers.

            • 3. Re: Camel - Mail - Using SMTP to sent  emil
              Claus Ibsen Master

              Let me know how it goes with your extension.

               

              We could probably add that as a fallback into camel-mail. However a unit test to demonstrate the issue is probably not easy to create.