Search in sources :

Example 1 with EmailTarget

use of org.broadleafcommerce.common.email.domain.EmailTarget in project BroadleafCommerce by BroadleafCommerce.

the class EmailServiceImpl method sendTemplateEmail.

public boolean sendTemplateEmail(String emailAddress, EmailInfo emailInfo, Map<String, Object> props) {
    if (!(emailInfo instanceof NullEmailInfo)) {
        EmailTarget emailTarget = emailReportingDao.createTarget();
        emailTarget.setEmailAddress(emailAddress);
        return sendTemplateEmail(emailTarget, emailInfo, props);
    } else {
        return true;
    }
}
Also used : NullEmailInfo(org.broadleafcommerce.common.email.service.info.NullEmailInfo) EmailTarget(org.broadleafcommerce.common.email.domain.EmailTarget)

Example 2 with EmailTarget

use of org.broadleafcommerce.common.email.domain.EmailTarget in project BroadleafCommerce by BroadleafCommerce.

the class MessageCreator method buildMimeMessagePreparator.

public MimeMessagePreparator buildMimeMessagePreparator(final Map<String, Object> props) {
    MimeMessagePreparator preparator = new MimeMessagePreparator() {

        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            EmailTarget emailUser = (EmailTarget) props.get(EmailPropertyType.USER.getType());
            EmailInfo info = (EmailInfo) props.get(EmailPropertyType.INFO.getType());
            boolean isMultipart = CollectionUtils.isNotEmpty(info.getAttachments());
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, info.getEncoding());
            message.setTo(emailUser.getEmailAddress());
            message.setFrom(info.getFromAddress());
            message.setSubject(info.getSubject());
            if (emailUser.getBCCAddresses() != null && emailUser.getBCCAddresses().length > 0) {
                message.setBcc(emailUser.getBCCAddresses());
            }
            if (emailUser.getCCAddresses() != null && emailUser.getCCAddresses().length > 0) {
                message.setCc(emailUser.getCCAddresses());
            }
            String messageBody = info.getMessageBody();
            if (messageBody == null) {
                messageBody = buildMessageBody(info, props);
            }
            message.setText(messageBody, true);
            for (Attachment attachment : info.getAttachments()) {
                ByteArrayDataSource dataSource = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType());
                message.addAttachment(attachment.getFilename(), dataSource);
            }
        }
    };
    return preparator;
}
Also used : MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) MimeMessage(javax.mail.internet.MimeMessage) EmailTarget(org.broadleafcommerce.common.email.domain.EmailTarget) EmailInfo(org.broadleafcommerce.common.email.service.info.EmailInfo) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource)

Aggregations

EmailTarget (org.broadleafcommerce.common.email.domain.EmailTarget)2 MimeMessage (javax.mail.internet.MimeMessage)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 EmailInfo (org.broadleafcommerce.common.email.service.info.EmailInfo)1 NullEmailInfo (org.broadleafcommerce.common.email.service.info.NullEmailInfo)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1 MimeMessagePreparator (org.springframework.mail.javamail.MimeMessagePreparator)1