Search in sources :

Example 26 with MimeMessageHelper

use of org.springframework.mail.javamail.MimeMessageHelper in project ArachneCentralAPI by OHDSI.

the class ArachneMailSender method send.

public void send(ArachneMailMessage mailMessage) {
    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper;
    try {
        helper = new MimeMessageHelper(message, true);
        helper.setSubject(mailMessage.getSubject());
        helper.setFrom(from, mailMessage.getFromPersonal());
        helper.setTo(mailMessage.getUser().getEmail());
        helper.setText(buildContent(mailMessage.getTemplate(), mailMessage.getParameters()), true);
        mailSender.send(message);
    } catch (MailConnectException e) {
        LOG.error(e.getMessage(), e);
        throw new MailSendException(e.getMessage());
    } catch (MessagingException | UnsupportedEncodingException ex) {
        LOG.error(ex.getMessage(), ex);
    } catch (MailSendException e) {
        LOG.error(e.getMessage(), e);
        throw new MailSendException("Failed to send e-mail. Please, contact to the administrator.");
    }
}
Also used : MailSendException(org.springframework.mail.MailSendException) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MailConnectException(com.sun.mail.util.MailConnectException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Aggregations

MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)26 MimeMessage (javax.mail.internet.MimeMessage)24 MessagingException (javax.mail.MessagingException)12 MailException (org.springframework.mail.MailException)9 Date (java.util.Date)7 Properties (java.util.Properties)5 JavaMailSenderImpl (org.springframework.mail.javamail.JavaMailSenderImpl)5 Async (org.springframework.scheduling.annotation.Async)5 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 MimeMessagePreparator (org.springframework.mail.javamail.MimeMessagePreparator)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SendmailMessage (org.opennms.netmgt.config.javamail.SendmailMessage)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)2 Service (org.springframework.stereotype.Service)2 Checks (com.khartec.waltz.common.Checks)1 IOUtilities (com.khartec.waltz.common.IOUtilities)1 StringUtilities (com.khartec.waltz.common.StringUtilities)1 OpcBizException (com.paascloud.provider.exceptions.OpcBizException)1