Esempio n. 1
0
 private Email createEmail(final String title, final String body) throws EmailException {
   Email email = new SimpleEmail();
   email.setHostName(host);
   email.setAuthentication(username, password);
   email.setSmtpPort(port);
   email.setSSLOnConnect(useSsl);
   email.setFrom(checkNotNullOrEmpty(from));
   email.addTo(checkNotNullOrEmpty(to));
   email.setSubject(title);
   email.setMsg(body);
   return email;
 }
  /**
   * Setup the comment e-mail
   *
   * @param blog {@link Blog} information
   * @param entry {@link Entry}
   * @param email Email message
   * @throws EmailException If there is an error preparing the e-mail message
   */
  protected void setupEmail(Blog blog, Entry entry, Email email) throws EmailException {
    email.setCharset(BlojsomConstants.UTF8);

    // If we have a mail session for the environment, use that
    if (_session != null) {
      email.setMailSession(_session);
    } else {
      // Otherwise, if there is a username and password for the mail server, use that
      if (!BlojsomUtils.checkNullOrBlank(_mailServerUsername)
          && !BlojsomUtils.checkNullOrBlank(_mailServerPassword)) {
        email.setHostName(_mailServer);
        email.setAuthentication(_mailServerUsername, _mailServerPassword);
      } else {
        email.setHostName(_mailServer);
      }
    }

    email.setFrom(blog.getBlogOwnerEmail(), "Blojsom Comment");

    String author = entry.getAuthor();
    if (BlojsomUtils.checkNullOrBlank(author)) {
      author = blog.getBlogOwner();
    }

    String authorEmail = blog.getBlogOwnerEmail();

    if (author != null) {
      try {
        User user = _fetcher.loadUser(blog, author);

        if (user == null) {
          authorEmail = blog.getBlogOwnerEmail();
        } else {
          authorEmail = user.getUserEmail();
          if (BlojsomUtils.checkNullOrBlank(authorEmail)) {
            authorEmail = blog.getBlogOwnerEmail();
          }
        }
      } catch (FetcherException e) {
      }
    }

    email.addTo(authorEmail, author);
    email.setSentDate(new Date());
  }
Esempio n. 3
0
  /**
   * Envia um e-mail para o usuário desejado, com uma nova senha de acesso para que o usuário possa
   * acessar novamente a sua conta mesmo depois de perder a senha.
   *
   * @param emailUsuario
   * @param novaSenha
   * @throws org.apache.commons.mail.EmailException
   */
  public static void enviarEmailRecuperacaoSenha(String emailUsuario, String novaSenha)
      throws EmailException {

    Email email = new SimpleEmail();
    email.setHostName(ConfMail.getHOST_NAME());
    email.setSmtpPort(ConfMail.getSMTP_PORT());
    email.setAuthentication(ConfMail.getMY_MAIL(), ConfMail.getMY_PASSWORD());
    email.setSSL(ConfMail.isSSL_CONNECT());

    email.setFrom(ConfMail.getFROM(), ConfMail.getNAME_FROM());
    email.setSubject("SALI - Recuperação de Senha de Acesso");
    email.setMsg(
        "Você solicitou a recuperação de senha de acesso ao SALI - Sistema de Auxílio no Aprendizado "
            + "da Língua Ínglesa.\nSeus dados de acesso agora são:\n\nEmail: "
            + emailUsuario
            + "\nSenha: "
            + novaSenha);
    email.addTo(emailUsuario);
    email.send();
  }