6 Replies Latest reply on Sep 3, 2007 7:59 PM by Madhav Inamti

    Seam mail ...

    Madhav Inamti Novice

      I am trying to send an email from my Seam application.

      I have the following classes

      Notification interface has a send method declared @Asynchronous

      NotificationBean @Stateless and implements the send method. invokes Renderer.render("/sendEmail.xhtml")

      The Bean gets invoked. The mail does not get sent.

      In my components.xml I have <core:dispatcher/> (Chapter 17: seam doc)

      I tried removing the @Asynchronous tag and the email is not sent. I have configured my smtp host, port , username, password.

      I suspect Renderer.render is not invoking the proper view. How do I check this. render returns a String. What is this string ? I could not find it in the docs.

      Also, I am outjecting the context variables needed to send the email in the Bean method.

      Thanks,
      M

        • 1. Re: Seam mail ...
          Pete Muir Master

          Post the error message (exception stack trace), your code, and output with Seam Mail debug enabled.

          • 2. Re: Seam mail ...
            Tomislav Jakopec Novice

            Another question about seam mail
            Its possible to use seam mail in classic jsp pages (not facelets)??

            I try with

            <%@ taglib uri="http://jboss.com/products/seam/mail" prefix="sm"%>
            


            and got error
            Cannot find tag library descriptor

            If is possible, please give me one example, default seam doc use facelets

            • 3. Re: Seam mail ...
              Pete Muir Master

              No, its a facelets only library for now. A good community contribution would be make the library run with JSP (it should work, it's just missing the .tld and the Tag classes) - the best way to achieve this would probably to port the library to the CDK.

              • 4. Re: Seam mail ...
                Tomislav Jakopec Novice

                My another question (desired behavior) is
                On my jboss as install mail server (I read about buni project), from app send mails, BUT I want that mail save in sent items of user mail account on jboss mail server. Is that possible, do you have link to tutorial.

                Then off course from my app read received mail on user mail account on jboss mail server. Naturally, after creation of user in our app we will create user on mail server. Then all benefits of mail account will get by mail server and in our app we will only communicate with mail server (without writing code to managing mails)

                • 5. Re: Seam mail ...
                  Pete Muir Master

                  If you want to keep a copy of items sent using Seam Mail, the best way is to add a bcc to a special address, and use a mail filter to direct it to the correct place. You'll need to ask over on buni.org for how to do this with Meldware.

                  • 6. Re: Seam mail ...
                    Madhav Inamti Novice

                    This is what I have...

                    The email page (regemail.xhtml)

                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:f="http://java.sun.com/jsf/core"
                     template="mailtemplate.xhtml">
                    
                     <ui:param name="subject" value="foo registration" />
                    
                     <ui:define name="body">
                     <p>Thank you for registering with foo.</p>
                     <p>Click on this link to confirm your registration <a href="http://www.foo.com"> foo </a></p>
                     <p>Happy foo</p>
                     </ui:define>
                    
                    </ui:composition>


                    The template (mailtemplate.xhtml)
                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                     xmlns:ui="http://java.sun.com/jsf/facelets"
                     xmlns:s="http://jboss.com/products/seam/taglib"
                     xmlns:m="http://jboss.com/products/seam/mail"
                     xmlns:h="http://java.sun.com/jsf/html"
                     xmlns:f="http://java.sun.com/jsf/core">
                    
                     <m:message>
                     <m:from name="foo" address="do-not-reply@foo.com" />
                     <m:to name="#{user.firstname} #{user.lastname}">#{user.email}</m:to>
                     <m:subject>#{subject}</m:subject>
                     <m:body>
                     <html>
                     <body>
                     <ui:insert name="body">
                     This is the default body, specified by the template.
                     </ui:insert>
                     </body>
                     </html>
                     <f:facet name="alternative">
                     <ui:insert name="alternative">
                     <h:outputText>Sorry, your mail reader doesn't support html.</h:outputText>
                     </ui:insert>
                     </f:facet>
                     </m:body>
                     </m:message>
                    
                     <ui:insert name="successMessage">
                     <html>
                     <body>
                     <p>An email has been sent to you. Please click on the link in the email to confirm your registration.</p>
                     </body>
                     </html>
                     </ui:insert>
                    </ui:composition>
                    



                    If I perform a renderer.render("/regemail.xhtml") it works fine. However, if I have a NotificationBean class defined and try to perform renderer.render in a method pf the NotificationBean, nothing happens. I do not see anything on the screen. The reason why I want a bean is because I need to send this email asynchronously.

                    Notification.java
                    package com.foo.session;
                    
                    import org.jboss.annotation.ejb.Local;
                    import org.jboss.seam.annotations.async.Asynchronous;
                    
                    @Local
                    public interface Notification {
                    
                     // I tried with the @Asynchronous annotation also
                    
                     public void notifyByEmail(String emailAddress, String firstName, String lastName) throws NotificationException;
                    
                    
                    }
                    



                    NotificationBean.java

                    package com.foo.session;
                    
                    import javax.ejb.Remove;
                    import javax.ejb.Stateless;
                    
                    import org.jboss.seam.annotations.In;
                    import org.jboss.seam.annotations.Name;
                    import org.jboss.seam.annotations.Out;
                    import org.jboss.seam.annotations.async.Asynchronous;
                    import org.jboss.seam.faces.Renderer;
                    
                    @Stateless
                    @Name("notification")
                    public class NotificationBean implements Notification {
                    
                     @In(create=true)
                     private Renderer renderer;
                    
                     public void notifyByEmail(String email, String fName, String lName) throws NotificationException {
                    
                     try {
                     System.out.println("*************************** Before Rendered ******************************");
                     String result = renderer.render("/regemail.xhtml");
                     System.out.println("*********************" + result + "*****************");
                     System.out.println("*************************** Rendered ******************************");
                     }
                     catch (Exception e) {
                     throw new NotificationException(e.getMessage());
                     }
                     }
                    
                    
                    }