Broadleaf Commerce 电子邮件 Java 配置

Broadleaf Commerce Email Java Config

使用 Broadleaf 5.2 版,其中所有/大多数配置都切换为基于 java。在尝试通过取消注释 blMessageCreator bean 定义并添加我自己的 smtp 服务器设置来在 CoreEmailConfig.java 中配置电子邮件后,我可以成功发送电子邮件,但是我注意到两个问题:

1) ThymeleafMessageCreator 似乎已从版本 5.x 中删除,我无法在发行说明或其他地方找到有关原因的描述。我更愿意使用 Thymeleaf 电子邮件模板,我可以添加我自己的 class 并且它工作正常但我仍然面临第二个问题,所以想知道是否还有其他原因将其删除?

2) 无论 BLC 框架尝试注入哪个 EmailInfo bean(即 blRegistrationEmailInfo、blForgotPasswordEmailInfo 等),它似乎总是注入 CoreEmailConfig.java 文件中的最后一个。在演示站点中,最后一个是 blReturnConfirmationEmailInfo。这是其他人在版本 5.x 或 5.2 中遇到的问题,特别是 spring 引导和 java 配置?

下面是CoreEmailConfig.java

@Configuration
public class CoreEmailConfig {
    /**
     * A dummy mail sender has been set to send emails for testing purposes only
     * To view the emails sent use "DevNull SMTP" (download separately) with the following setting: 
     *   Port: 30000
     */
    @Bean
    public JavaMailSender blMailSender() {
        JavaMailSenderImpl sender = new JavaMailSenderImpl();
        sender.setHost("");
        sender.setPort(587);
        sender.setProtocol("smtp");
        sender.setUsername("");
        sender.setPassword("");
        Properties javaMailProps = new Properties();
        javaMailProps.setProperty("mail.smtp.starttls.enable", "true");
        javaMailProps.setProperty("mail.smtp.auth", "true");
        javaMailProps.setProperty("mail.smtp.timeout", "25000");
        sender.setJavaMailProperties(javaMailProps);
        return sender;
    }

    /**
     * Uncomment this bean to send real emails
     */
    @Bean
    @Autowired
    public MessageCreator blMessageCreator(@Qualifier("blEmailTemplateEngine") TemplateEngine tlTemplateEngine, @Qualifier("blMailSender") JavaMailSender mailSender) {
        return new ThymeleafMessageCreator(tlTemplateEngine, mailSender);
    }

//    @Bean
//    @Autowired
//    public MessageCreator blMessageCreator(@Qualifier("blMailSender") JavaMailSender mailSender) {
//        return new NullMessageCreator(mailSender);
//    }

    @Bean
    public EmailInfo blEmailInfo() {
        EmailInfo info = new EmailInfo();
        info.setFromAddress("");
        info.setSendAsyncPriority("2");
        info.setSendEmailReliableAsync("false");
        return info;
    }

    @Bean
    public EmailInfo blRegistrationEmailInfo() {
        EmailInfo info = blEmailInfo();
        info.setSubject("You have successfully registered!");
        info.setEmailTemplate("register-email");
        return info;
    }

    @Bean
    public EmailInfo blForgotPasswordEmailInfo() {
        EmailInfo info = blEmailInfo();
        info.setSubject("Reset password request");
        info.setEmailTemplate("resetPassword-email");
        return info;
    }

    @Bean
    public EmailInfo blOrderConfirmationEmailInfo() {
        EmailInfo info = blEmailInfo();
        info.setSubject("Your order with The Heat Clinic");
        info.setEmailTemplate("orderConfirmation-email");
        return info;
    }

    @Bean
    public EmailInfo blFulfillmentOrderTrackingEmailInfo() {
        EmailInfo info = blEmailInfo();
        info.setSubject("Your order with The Heat Clinic Has Shipped");
        info.setEmailTemplate("fulfillmentOrderTracking-email");
        return info;
    }

    @Bean
    public EmailInfo blReturnAuthorizationEmailInfo() {
        EmailInfo info = blEmailInfo();
        info.setSubject("Your return with The Heat Clinic");
        info.setEmailTemplate("returnAuthorization-email");
        return info;
    }

    @Bean
    public EmailInfo blReturnConfirmationEmailInfo() {
        EmailInfo info = blEmailInfo();
        info.setSubject("Your return with The Heat Clinic");
        info.setEmailTemplate("returnConfirmation-email");  
        return info;
    }
}

1) ThymeleafMessageCreator seems to have been removed from version 5.x, I can't find a description in release notes or elsewhere for the reason. I would prefer to use Thymeleaf email templates, I can add my own class back and it works ok but I still face the second issue, so was wondering if there was another reason to remove it?

在添加 Thymeleaf 3 支持时,这在 5.1 中进行了更改,详细信息在 5.0 到 5.1 的迁移指南中,更具体地在这里:https://www.broadleafcommerce.com/docs/core/current/migration-notes/5.1-thymeleaf-migration

请注意,在Demo项目中,Thymeleaf Presentation的依赖似乎不在Core项目的POM文件中,如果您希望将EmailConfig保留在Core中,您可能需要自己添加它模块。

2) Regardless of which EmailInfo bean the BLC framework tries to inject (i.e. blRegistrationEmailInfo, blForgotPasswordEmailInfo etc...), it seems to always inject the last one in the CoreEmailConfig.java file. In the demo site the last one is blReturnConfirmationEmailInfo. Is this an issue encountered by others in version 5.x or 5.2 specifically with the spring boot and java configs?

从 blEmailInfo() 方法中删除 @Bean 注释,它导致在所有 bl*EmailInfo 方法中重用相同的 EmailInfo 对象,而不是使用新对象。

@Bean

public EmailInfo blEmailInfo() {
    EmailInfo info = new EmailInfo();
    info.setFromAddress("");
    info.setSendAsyncPriority("2");
    info.setSendEmailReliableAsync("false");
    return info;
}