Search in sources :

Example 1 with DefaultMailService

use of com.autentia.tnt.mail.DefaultMailService in project TNTConcept by autentia.

the class SiiBean method sendReportEmail.

public void sendReportEmail(String report) {
    if (report != null) {
        Map<InputStream, String> attachments = new ConcurrentHashMap<>();
        String filename = reportName();
        attachments.put(getStreamReport(report), filename);
        String subject = "SII_" + filename.split(".csv")[0];
        ExecutorService executor = Executors.newFixedThreadPool(1);
        // Runnable, return void, submit and run the task async
        executor.submit(() -> {
            try {
                String[] recipients = to.trim().split("[;,]");
                MailService mailService = (DefaultMailService) SpringUtils.getSpringBean("mailService");
                mailService.sendOutputStreams(recipients, subject, "", attachments);
                context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Email enviado correctamente", null));
            } catch (MessagingException e) {
                System.err.println(e.getMessage());
            }
        });
        executor.shutdown();
    }
}
Also used : MailService(com.autentia.tnt.mail.MailService) DefaultMailService(com.autentia.tnt.mail.DefaultMailService) MessagingException(javax.mail.MessagingException) ExecutorService(java.util.concurrent.ExecutorService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) FacesMessage(javax.faces.application.FacesMessage) DefaultMailService(com.autentia.tnt.mail.DefaultMailService)

Example 2 with DefaultMailService

use of com.autentia.tnt.mail.DefaultMailService in project TNTConcept by autentia.

the class RequestHolidayBean method sendEmail.

protected void sendEmail() {
    final DefaultMailService mailService = (DefaultMailService) SpringUtils.getSpringBean("mailService");
    final Collection<String> mailSendToHolidayApprovers = ConfigurationUtil.getDefault().getMailSendToHolidayApprovers();
    for (String sendTo : mailSendToHolidayApprovers) {
        final String name = this.search.getUserRequest().getName();
        String subject = "Solicitud de vacaciones para " + name;
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy" + "");
        final String beginDate = dateFormat.format(this.requestHoliday.getBeginDate());
        final String finalDate = dateFormat.format(this.requestHoliday.getFinalDate());
        final String newLine = "</div><div>";
        String messageBody = ("<div>Usuario: ").concat("<b>" + name + "</b>").concat(newLine).concat("Fecha de inicio: ").concat("<b>" + beginDate + "</b>").concat(newLine).concat("Fecha de fin: ").concat("<b>" + finalDate + "</b>").concat(newLine).concat("Comentarios: ").concat(this.requestHoliday.getUserComment()).concat(newLine);
        mailService.sendHtml(sendTo, subject, messageBody);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) DefaultMailService(com.autentia.tnt.mail.DefaultMailService)

Example 3 with DefaultMailService

use of com.autentia.tnt.mail.DefaultMailService in project TNTConcept by autentia.

the class AdminHolidayBean method sendEmail.

protected void sendEmail() {
    final DefaultMailService mailService = (DefaultMailService) SpringUtils.getSpringBean("mailService");
    final Collection<String> mailNotificationReceivers = new ArrayList<String>(ConfigurationUtil.getDefault().getMailSendToHolidayApprovers());
    mailNotificationReceivers.add(this.adminHoliday.getUserRequest().getEmail());
    for (String sendTo : mailNotificationReceivers) {
        final String name = this.adminHoliday.getUserRequest().getName();
        String subject = "Solicitud de vacaciones de " + name + "[" + getState() + "]";
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy" + "");
        final String beginDate = dateFormat.format(this.adminHoliday.getBeginDate());
        final String finalDate = dateFormat.format(this.adminHoliday.getFinalDate());
        final String newLine = "</div><div>";
        String messageBody = ("<div>Usuario: ").concat("<b>" + name + "</b>").concat(newLine).concat("Fecha de inicio: ").concat("<b>" + beginDate + "</b>").concat(newLine).concat("Fecha de fin: ").concat("<b>" + finalDate + "</b>").concat(newLine).concat("Comentarios: ").concat(this.adminHoliday.getUserComment()).concat(newLine);
        mailService.sendHtml(sendTo, subject, messageBody);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) DefaultMailService(com.autentia.tnt.mail.DefaultMailService)

Example 4 with DefaultMailService

use of com.autentia.tnt.mail.DefaultMailService in project TNTConcept by autentia.

the class LinkBean method sendMail.

public void sendMail(Link link, String mailAddress) {
    DefaultMailService mailService = getMailService();
    try {
        ExternalContext externalContext = getFacesExternalContext();
        HttpServletRequest req = (HttpServletRequest) externalContext.getRequest();
        String verificationLink = buildResetPasswordVerificationLink(req, link);
        mailService.send(mailAddress, "[RESETEO DE CONTRASEÑA] Email de verificación", "Haz click en el siguiente link para verificar que eres tú si quieres cambiar la contraseña: " + verificationLink);
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MessagingException(javax.mail.MessagingException) ExternalContext(javax.faces.context.ExternalContext) DefaultMailService(com.autentia.tnt.mail.DefaultMailService)

Example 5 with DefaultMailService

use of com.autentia.tnt.mail.DefaultMailService in project TNTConcept by autentia.

the class UserBean method resetPassword.

/**
 * Reset current user password
 *
 * @return "userPasswordReset"
 */
public String resetPassword() {
    // get random words from properties, depending on locale
    String[] rnd0 = FacesUtils.formatMessage("AuthenticationManager.randomWords0").split(",");
    String[] rnd1 = FacesUtils.formatMessage("AuthenticationManager.randomWords1").split(",");
    String[] rnd2 = FacesUtils.formatMessage("AuthenticationManager.randomWords2").split(",");
    String[] rnd3 = FacesUtils.formatMessage("AuthenticationManager.randomWords3").split(",");
    String[] rnd4 = FacesUtils.formatMessage("AuthenticationManager.randomWords4").split(",");
    // Change user password
    changedPassword = authManager.resetPassword(user, rnd0, rnd1, rnd2, rnd3, rnd4);
    if (!ConfigurationUtil.getDefault().isLdapProviderEnabled()) {
        manager.updateEntity(user, this.isUseAgreementYearDuration());
    }
    DefaultMailService mailService = (DefaultMailService) SpringUtils.getSpringBean("mailService");
    try {
        mailService.send(user.getEmail(), "Reseteo de contraseña de TnT", "Tu nueva contraseña es: " + changedPassword);
    } catch (MessagingException e) {
        log.warn(e.getCause());
    }
    return "userPasswordReset";
}
Also used : MessagingException(javax.mail.MessagingException) DefaultMailService(com.autentia.tnt.mail.DefaultMailService)

Aggregations

DefaultMailService (com.autentia.tnt.mail.DefaultMailService)5 MessagingException (javax.mail.MessagingException)3 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 MailService (com.autentia.tnt.mail.MailService)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 FacesMessage (javax.faces.application.FacesMessage)1 ExternalContext (javax.faces.context.ExternalContext)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1