4 Replies Latest reply on Dec 21, 2008 3:13 PM by Jim Gallagher

    Issue sending email

    Jim Gallagher Newbie

      I have a problem sending an email, described below:

      On my web application, I have a link for forgotten passwords.
      The user enters their userid
      My processor retrieves the name, email address and password from the database
      A bean in placed in conversation scope with these details
      I run Renderer.render on the email xhtml file, hoping to read the details from the bean
      It constantly fails trying to find the email address, which should come from the bean.

      My processor code:

      public class ForgottenPasswordAction implements ForgottenPassword {

           private Log log;

           private EntityManager entityManager;

           @In(create = true)
           private HelperPassword helperpassword;

           private PasswordRetrieval passwordretrieval;

           FacesMessages facesMessages;

           @In(create = true)
           private Renderer renderer;

           public String retrievePassword() {
                log.info("Retrieving password for " + passwordretrieval.getUsername());
                try {
                     helperpassword = (HelperPassword) entityManager.createQuery(
                               "from Helper where username = :username").setParameter(
                               "username", passwordretrieval.getUsername())
                } catch (Exception e) {
                     facesMessages.add("Technical error - cannot send password!");
                     return null;
                if (helperpassword.getEmail().equals(null)
                          || helperpassword.getEmail().equals("")) {
                               .add("Email address not valid - cannot send password!");
                     return null;
                try {
                     System.out.println("Email address: " + helperpassword.getEmail());
                     facesMessages.add("Email sent successfully");
                     return null;
                } catch (Exception e) {
                     facesMessages.add("Email sending failed: " + e.getMessage());
                     return null;

      My bean code:

      @Table(name = "helpers_personal")
      public class HelperPassword implements Serializable {

           private static final long serialVersionUID = 1L;

           @GeneratedValue(strategy = GenerationType.AUTO)
           @Column(name = "ID")
           private int id;

           @Column(name = "Firstname")
           private String firstName;

           @Column(name = "SecondName")
           private String secondName;

           @Column(name = "Email")
           private String email;

           @Column(name = "username")
           private String userName;

           @Column(name = "password")
           private String password;

           public HelperPassword() {


           public String getEmail() {
                return email;

           public void setEmail(String email) {
                this.email = email;

           public String getFirstName() {
                return firstName;

           public void setFirstName(String firstName) {
                this.firstName = firstName;

           public int getId() {
                return id;

           public void setId(int id) {
                this.id = id;

           public String getPassword() {
                return password;

           public void setPassword(String password) {
                this.password = password;

           public String getSecondName() {
                return secondName;

           public void setSecondName(String secondName) {
                this.secondName = secondName;

           public String getUserName() {
                return userName;

           public void setUserName(String userName) {
                this.userName = userName;


      My email template:

      <m:message xmlns="http://www.w3.org/1999/xhtml"
           <m:from name="OUTPUT ADDRESS" address="ADDRESS REMOVED" />
           <m:to name="Jim" address="#{helperpassword.email}" />
           <m:subject>Password Reminder</m:subject>
           <m:body type="plain">
                <p />
                <h:outputText value="Dear Jim" />,
                <p />You requested a password reminder. The password for your account is below:
                <p />Password: <h:outputText value="#{helperpassword.password}" />
                <p />Regards,
                <p />Fred