Search in sources :

Example 6 with EmailInfo

use of org.broadleafcommerce.common.email.service.info.EmailInfo 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)

Example 7 with EmailInfo

use of org.broadleafcommerce.common.email.service.info.EmailInfo in project BroadleafCommerce by BroadleafCommerce.

the class EmailNotificationPasswordUpdatedHandler method passwordChanged.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void passwordChanged(PasswordReset passwordReset, Customer customer, String newPassword) {
    Locale localeToUse = null;
    org.broadleafcommerce.common.locale.domain.Locale blLocale = customer.getCustomerLocale();
    if (blLocale != null) {
        String[] splitLocale = blLocale.getLocaleCode().split("_");
        if (splitLocale.length > 1) {
            localeToUse = new Locale(splitLocale[0], splitLocale[1]);
        } else {
            localeToUse = new Locale(splitLocale[0]);
        }
    }
    if (localeToUse == null) {
        localeToUse = getPasswordResetEmailDefaultLocale();
    }
    String subject = getPasswordResetEmailSubject().get(localeToUse);
    if (subject == null) {
        LOG.warn("Unable to find an email subject for customer locale: " + localeToUse.toString() + ". Using default locale instead.");
        subject = getPasswordResetEmailSubject().get(getPasswordResetEmailDefaultLocale());
    }
    String template = getPasswordResetEmailTemplate().get(localeToUse);
    if (template == null) {
        LOG.warn("Unable to find an email template for customer locale: " + localeToUse.toString() + ". Using default locale instead.");
        template = getPasswordResetEmailTemplate().get(getPasswordResetEmailDefaultLocale());
    }
    EmailInfo info = new EmailInfo();
    info.setFromAddress(getPasswordResetEmailFromAddress());
    info.setSubject(subject);
    info.setEmailTemplate(template);
    info.setSendEmailReliableAsync(String.valueOf(passwordReset.isSendResetEmailReliableAsync()));
    HashMap vars = constructPasswordChangeEmailTemplateVariables(customer, newPassword);
    emailService.sendTemplateEmail(passwordReset.getEmail(), info, vars);
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) EmailInfo(org.broadleafcommerce.common.email.service.info.EmailInfo)

Example 8 with EmailInfo

use of org.broadleafcommerce.common.email.service.info.EmailInfo in project BroadleafCommerce by BroadleafCommerce.

the class AdminSpringBootTestConfiguration method blForgotPasswordEmailInfo.

@Bean
public EmailInfo blForgotPasswordEmailInfo() {
    EmailInfo info = blEmailInfo();
    info.setSubject("Reset password request");
    info.setEmailTemplate("resetPassword-email");
    return info;
}
Also used : EmailInfo(org.broadleafcommerce.common.email.service.info.EmailInfo) MapFactoryBean(org.springframework.beans.factory.config.MapFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 9 with EmailInfo

use of org.broadleafcommerce.common.email.service.info.EmailInfo in project BroadleafCommerce by BroadleafCommerce.

the class AdminSpringBootTestConfiguration method blReturnAuthorizationEmailInfo.

@Bean
public EmailInfo blReturnAuthorizationEmailInfo() {
    EmailInfo info = blEmailInfo();
    info.setSubject("Your return with The Heat Clinic");
    info.setEmailTemplate("returnAuthorization-email");
    return info;
}
Also used : EmailInfo(org.broadleafcommerce.common.email.service.info.EmailInfo) MapFactoryBean(org.springframework.beans.factory.config.MapFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 10 with EmailInfo

use of org.broadleafcommerce.common.email.service.info.EmailInfo in project BroadleafCommerce by BroadleafCommerce.

the class AdminSpringBootTestConfiguration method blOrderConfirmationEmailInfo.

@Bean
public EmailInfo blOrderConfirmationEmailInfo() {
    EmailInfo info = blEmailInfo();
    info.setSubject("Your order with The Heat Clinic");
    info.setEmailTemplate("orderConfirmation-email");
    return info;
}
Also used : EmailInfo(org.broadleafcommerce.common.email.service.info.EmailInfo) MapFactoryBean(org.springframework.beans.factory.config.MapFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

EmailInfo (org.broadleafcommerce.common.email.service.info.EmailInfo)15 Bean (org.springframework.context.annotation.Bean)8 MapFactoryBean (org.springframework.beans.factory.config.MapFactoryBean)7 NullEmailInfo (org.broadleafcommerce.common.email.service.info.NullEmailInfo)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 ObjectMessage (javax.jms.ObjectMessage)1 Session (javax.jms.Session)1 MimeMessage (javax.mail.internet.MimeMessage)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 EmailTarget (org.broadleafcommerce.common.email.domain.EmailTarget)1 EmailException (org.broadleafcommerce.common.email.service.exception.EmailException)1 MessageCreator (org.springframework.jms.core.MessageCreator)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1 MimeMessagePreparator (org.springframework.mail.javamail.MimeMessagePreparator)1 Test (org.testng.annotations.Test)1