5 Replies Latest reply on Apr 16, 2011 7:02 AM by Ranganathan Kaliyur Mannar

    Seam Mail Dynamic configuration

    Zahid Maqbool Newbie

      Hi,


      I have been trying to seam mail. It works fine. But I want this mail configuration to be dynamic and not from the config files.  I tried with Mail Session, but it still uses the same session. Can anyone point me to the right direction.


      Thanks!!

        • 1. Re: Seam Mail Dynamic configuration
          Pete Muir Master

          Write a component that extends org.jboss.seam.mail.MailSession and return's the session you want in an @Unwrap method.

          • 2. Re: Seam Mail Dynamic configuration
            Zahid Maqbool Newbie

            Thank you very much Pete... It would be really nice if you can point me to the right place, like some example, any place mentioned in the reference docs.

            • 3. Re: Seam Mail Dynamic configuration
              tomek szzzaaos Newbie

              In case anyone need it:


              @Name("org.jboss.seam.mail.mailSession")
              @Install(value=true, precedence=Install.APPLICATION)
              @Scope(APPLICATION)
              @BypassInterceptors
              public class EmailConfiguration extends org.jboss.seam.mail.MailSession implements Serializable  {
              
                  public static String      EMAIL_SMTP_HOST;
                  public static int      EMAIL_SMTP_PORT;
                  public static String      EMAIL_USER;
                  public static String      EMAIL_PASSWORD;
                  public static boolean      EMAIL_SSL;
                  public static boolean      EMAIL_DEBUG;
              
                  public EmailConfiguration(){
                   this(null);          
                  }
                  public EmailConfiguration(String transport){
                      super(transport);
              
              //those values could be of course read from external file or database...whatever
                      setHost(EMAIL_SMTP_HOST);
                   setPort(EMAIL_SMTP_PORT);                    
                   setUsername(EMAIL_USER);
                   setPassword(EMAIL_PASSWORD);          
                      setSsl(EMAIL_SSL);
                   setDebug(EMAIL_DEBUG);
                  }
              
              }
              

              • 4. Re: Seam Mail Dynamic configuration
                Prajwal Boloor Newbie

                Hi Tomek,


                I am currently working on a similar requirement of dynamically setting the mail properties from DB.
                In the example above how can I get the hostname and other properties from DB and set it to mailsession??
                I tried injecting EntityManager to retrieve the values from DB but em is always null as i am trying to reference it in the constructor.
                please help me as i have tried searing for some reference and no progress so far.


                Thanks in advance.


                Regards,
                Prajwal

                • 5. Re: Seam Mail Dynamic configuration
                  Ranganathan Kaliyur Mannar Newbie

                  Hi Tomek Szpinda,
                  I tried your sample to have a dynamic mail configuration. but I get a


                  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)
                  



                  I am unable to understand why. Can someone please explain what I am doing wrong?



                  Thanks,
                  Ranga.