Search in sources :

Example 1 with MailService

use of com.autentia.tnt.mail.MailService 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 MailService

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

the class ActivityEvidenceNotificationBean_IT method setup.

@Before
public void setup() {
    // load test application context including security configuration
    ApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext-test.xml");
    SpringUtilsForTesting.configure(appCtx);
    // each test starts its own transaction
    sessionFactory = HibernateUtil.getSessionFactory();
    sessionFactory.openSession();
    sessionFactory.getCurrentSession().beginTransaction();
    // a user is required in the database to load the security context
    SpringUtilsForTesting.loadPrincipalInSecurityContext("admin");
    mailService = Mockito.mock(MailService.class);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) MailService(com.autentia.tnt.mail.MailService) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Before(org.junit.Before)

Aggregations

MailService (com.autentia.tnt.mail.MailService)2 DefaultMailService (com.autentia.tnt.mail.DefaultMailService)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 FacesMessage (javax.faces.application.FacesMessage)1 MessagingException (javax.mail.MessagingException)1 Before (org.junit.Before)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1