Broadleaf Microservices
  • v1.0.0-latest-prod

Using Amazon SES SDK To Send Emails with Broadleaf Notification Service

Overview

Broadleaf provides out of box configuration and helper classes that can be used to send notifications using Amazon SES

Configuring the SESMessageSender

The Broadleaf SESMessageSender, uses the Amazon SES SDK to send email notifications.

The following configuration is all that is needed.

import org.springframework.context.annotation.*;
import com.broadleafcommerce.notification.service.*;
import com.broadleafcommerce.notification.service.integration.SESMessageSender;

@Configuration
public class MyNotificationConfiguration {

    // Step 1: Configure a SESMessageSender
    @Bean
    SESMessageSender sesMailSender() {
        // The Broadleaf SESMessageSender requires a client.
        // See SES documentation for configuration and setup.
        AmazonSimpleEmailService awsClient =
                AmazonSimpleEmailServiceClientBuilder.standard()
                        .withCredentials(getCredentials())
                        .withRegion(Regions.US_EAST_1).build();
        return new SESMessageSender(awsClient);
    }

    // Step 2: Register an EMAIL handler with the NotificationService
    @Bean
    NotificationHandler sesMailNotificationHandler(ThymeleafMessageBuilder builder,
            SESMessageSender sender) {
        return new DefaultNotificationHandler(builder, sender);
    }
}
Note
In SES development mode, all emails (from and to) must be verified emails. See SES documentation for more information.

About the example

The above configuration uses the ThymeleafMessageBuilder. Thymeleaf provides capabilities to provide rich html emails based on templates. Refer to MessageBuilders for more information.

To apply, the configuration must be component scanned by your application. A typical approach is to add the configurations to SpringBoot’s META-INF/spring.factories file.