public void apply() {
    User user = db.emailExist(email);
    if (user.getEmail() != null) {
      Properties props = System.getProperties();

      props.put("mail.smtp.host", "smtp.gmail.com");
      props.put("mail.from", "*****@*****.**");
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.port", "587");
      props.setProperty("mail.debug", "true");

      Session session = Session.getDefaultInstance(props);
      try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("*****@*****.**"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));

        message.setSubject("This is the Subject Line!");

        String newPw = gen.nextSessionId();
        user.setPassword(newPw);
        if (db.changePassword(user)) {
          message.setText(
              "Hi,\n \n You requested a reset of your password."
                  + "\n \n Your new password is now: "
                  + newPw);
          Transport transport = session.getTransport("smtp");
          transport.connect("*****@*****.**", "catering123");
          transport.sendMessage(message, message.getAllRecipients());
          transport.close();
          System.out.println("Sent message successfully....");
        }
        FacesMessage fm = new FacesMessage("Email sent");
        FacesContext.getCurrentInstance().addMessage(null, fm);
      } catch (MessagingException mex) {
        mex.printStackTrace();
        //   }
      }
    } else {
      FacesMessage fm = new FacesMessage("Email was not found");
      FacesContext.getCurrentInstance().addMessage(null, fm);
    }
  }