4 Replies Latest reply on Apr 26, 2011 10:51 AM by kmranganathan

    Dynamic Mail Configuration for gmail - issue

    kmranganathan

      Hi,
      I am developing an application where I need to dynamically setup the email configuration - there are many users and each have their own gmail id. So, I write my own configuraion and set the user name and password dynamically:



      @Name("org.jboss.seam.mail.mailSession")
      @Install(value = true, precedence = Install.APPLICATION)
      @Scope(ScopeType.APPLICATION)
      @BypassInterceptors
      class EmailConfiguration extends org.jboss.seam.mail.MailSession implements Serializable
      {
      



      and render each time as


      EmailConfiguration myMailSession = new EmailConfiguration(is, passwd);
      Contexts.getEventContext().set("session", myMailSession);
      renderer.render("/Mail.xhtml");
      



      But, I get the following exception:


      org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.mail.mailSession



      Underlying exception is:



      Caused by: java.lang.IllegalAccessException: Class org.jboss.seam.Component can not access a member of class com.appspace.hrms.action.EmailConfiguration with modifiers "public"
      16:16:14,129 ERROR [STDERR]      at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
      16:16:14,129 ERROR [STDERR]      at java.lang.Class.newInstance0(Class.java:349)
      16:16:14,129 ERROR [STDERR]      at java.lang.Class.newInstance(Class.java:308)
      16:16:14,129 ERROR [STDERR]      at org.jboss.seam.Component.instantiateJavaBean(Component.java:1438)
      16:16:14,129 ERROR [STDERR]      at org.jboss.seam.Component.instantiate(Component.java:1359)
      16:16:14,129 ERROR [STDERR]      at org.jboss.seam.Component.newInstance(Component.java:2122)
      



      What am I doing wrong?

        • 1. Re: Dynamic Mail Configuration for gmail - issue
          lvdberg

          Hi,


          It is not clear to me why you want to change mail handling for each related person. Do you mean that you have to connect to each of their servers directly, or do you mean that you just need to send an email.


          If it is the first, I would look for direct interaction with the JavaMail Api, within a Seam bean.


          If it is the second, it's just changing the recipient name in the template.



          Leo

          • 2. Re: Dynamic Mail Configuration for gmail - issue
            kmranganathan

            Hi,
            Basically each user has his/her own gmail id. When a user logs in and wants to send email, it needs to be sent from his/her id. So, I need to connect to the gmail SMTP server with that user's email id and password for this to happen. So, I end up configuring every time.


            Ok, so looks like I will have to write Java mail myself - which is easy, but rendering wouldn't be as easy as in seam.

            • 3. Re: Dynamic Mail Configuration for gmail - issue
              cosmo

              Regarding to your first attempt, did you tried injecting(@In or Component.getInstance()) your EmailConfiguration component instead of construct it yourself?

              • 4. Re: Dynamic Mail Configuration for gmail - issue
                kmranganathan

                I tried Component.getInstance(), but got a ClassCastException - I then checked seam MailSession.java code, I see that Unwrap method has been used to return a java.mail.Session instance. hmm...this is interesting


                So, propably this was the reason I got the error initially. This also means that I haven't coded my custom configuration correctly. Have to figure that out.