Search in sources :

Example 11 with MailException

use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.

the class EmailActionProcessor method sendEmail.

private void sendEmail(RuleActionBean ruleAction, UserAccountBean ub, String body, String subject) throws OpenClinicaSystemException {
    logger.info("Sending email...");
    try {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
        helper.setFrom(EmailEngine.getAdminEmail());
        helper.setTo(processMultipleImailAddresses(((EmailActionBean) ruleAction).getTo().trim()));
        helper.setSubject(subject);
        helper.setText(body);
        mailSender.send(mimeMessage);
        System.out.println("Sending Email thru Email Action");
        logger.debug("Email sent successfully on {}", new Date());
    } catch (MailException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.getMessage());
    } catch (MessagingException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.getMessage());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Date(java.util.Date)

Example 12 with MailException

use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.

the class NotificationActionProcessor method sendEmail.

private void sendEmail(RuleActionBean ruleAction, ParticipantDTO pDTO) throws OpenClinicaSystemException {
    logger.info("Sending email...");
    try {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
        helper.setFrom(EmailEngine.getAdminEmail());
        helper.setTo(pDTO.getEmailAccount());
        helper.setSubject(pDTO.getEmailSubject());
        helper.setText(pDTO.getMessage());
        mailSender.send(mimeMessage);
        logger.debug("Email sent successfully on {}", new Date());
    } catch (MailException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.getMessage());
    } catch (MessagingException me) {
        logger.error("Email could not be sent");
        throw new OpenClinicaSystemException(me.getMessage());
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) Date(java.util.Date)

Example 13 with MailException

use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.

the class SystemController method sendEmail.

public String sendEmail(JavaMailSenderImpl mailSender, String emailSubject, String message) throws OpenClinicaSystemException {
    logger.info("Sending email...");
    try {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
        helper.setFrom(EmailEngine.getAdminEmail());
        helper.setTo("oc123@openclinica.com");
        helper.setSubject(emailSubject);
        helper.setText(message);
        mailSender.send(mimeMessage);
        return "ACTIVE";
    } catch (MailException me) {
        return "INACTIVE";
    } catch (MessagingException me) {
        return "INACTIVE";
    }
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MailException(org.springframework.mail.MailException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Example 14 with MailException

use of org.springframework.mail.MailException in project OpenClinica by OpenClinica.

the class SecureController method sendEmail.

public Boolean sendEmail(String to, String from, String subject, String body, Boolean htmlEmail, String successMessage, String failMessage, Boolean sendMessage) throws Exception {
    Boolean messageSent = true;
    try {
        JavaMailSenderImpl mailSender = (JavaMailSenderImpl) SpringServletAccess.getApplicationContext(context).getBean("mailSender");
        //@pgawade 09-Feb-2012 #issue 13201 - setting the "mail.smtp.localhost" property to localhost when java API is not able to
        //retrieve the host name
        Properties javaMailProperties = mailSender.getJavaMailProperties();
        if (null != javaMailProperties) {
            if (javaMailProperties.get("mail.smtp.localhost") == null || ((String) javaMailProperties.get("mail.smtp.localhost")).equalsIgnoreCase("")) {
                javaMailProperties.put("mail.smtp.localhost", "localhost");
            }
        }
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, htmlEmail);
        helper.setFrom(from);
        helper.setTo(processMultipleImailAddresses(to.trim()));
        helper.setSubject(subject);
        helper.setText(body, true);
        mailSender.send(mimeMessage);
        if (successMessage != null && sendMessage) {
            addPageMessage(successMessage);
        }
        logger.debug("Email sent successfully on {}", new Date());
    } catch (MailException me) {
        me.printStackTrace();
        if (failMessage != null && sendMessage) {
            addPageMessage(failMessage);
        }
        logger.debug("Email could not be sent on {} due to: {}", new Date(), me.toString());
        messageSent = false;
    }
    return messageSent;
}
Also used : JavaMailSenderImpl(org.springframework.mail.javamail.JavaMailSenderImpl) MimeMessage(javax.mail.internet.MimeMessage) MailException(org.springframework.mail.MailException) Properties(java.util.Properties) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) Date(java.util.Date)

Example 15 with MailException

use of org.springframework.mail.MailException in project bamboobsc by billchen198318.

the class MailClientUtils method send.

public static void send(String from, String to, String[] cc, String[] bcc, String[] fileNames, File[] files, String subject, String text) throws MailException, Exception {
    if (mailSender == null) {
        throw new Exception("null mailSender!");
    }
    if (StringUtils.isBlank(from) || StringUtils.isBlank(to)) {
        throw new Exception("from and to is required!");
    }
    if (fileNames != null && files != null) {
        if (fileNames.length != files.length) {
            throw new Exception("File parameter error!");
        }
    }
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true, Constants.BASE_ENCODING);
    helper.setFrom(from);
    helper.setTo(to.endsWith(";") ? to.substring(0, to.length() - 1) : to);
    helper.setSubject(subject);
    helper.setText(text, true);
    if (null != cc && cc.length > 0) {
        helper.setCc(cc);
    }
    if (null != bcc && bcc.length > 0) {
        helper.setBcc(bcc);
    }
    for (int i = 0; fileNames != null && i < fileNames.length; i++) {
        helper.addAttachment(fileNames[i], files[i]);
    }
    mailSender.send(message);
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) MailException(org.springframework.mail.MailException)

Aggregations

MailException (org.springframework.mail.MailException)15 MimeMessage (javax.mail.internet.MimeMessage)11 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)9 Date (java.util.Date)8 MessagingException (javax.mail.MessagingException)7 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)4 RegistrarException (cz.metacentrum.perun.registrar.exceptions.RegistrarException)3 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)3 ApplicationMail (cz.metacentrum.perun.registrar.model.ApplicationMail)3 MailText (cz.metacentrum.perun.registrar.model.ApplicationMail.MailText)3 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)3 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)3 Application (cz.metacentrum.perun.registrar.model.Application)2 AuthenticationFailedException (javax.mail.AuthenticationFailedException)2 NoSuchProviderException (javax.mail.NoSuchProviderException)2 MailAuthenticationException (org.springframework.mail.MailAuthenticationException)2