Configure Email - BloomReach Experience - Open Source CMS

Configure Email

Introduction

Goal

Configure the SMTP server for your Bloomreach Cloud stack to enable your Bloomreach Experience Manager implementation to send email messages.

Procedure

To enable the applications deployed in your Bloomreach Cloud stack to send email messages, you need credentials and the host configuration string for the SMTP server. BloomReach can provide these on request. To do so, BloomReach will ask you on behalf of AWS to put some entries into your DNS to prove you own the domain. It is best not to wait too long with entering these entries. After the confirmation, BloomReach will upload a mail configuration file to your stack. This configuration file will contain the following properties:

brc.mail.smtp.host=...
brc.mail.smtp.username=...
brc.mail.smtp.password=...
brc.mail.smtp.port=...

When deploying a distribution, you need to include this configuration file for use as Java system properties. From now on your code can use the configuration from the file as shown below in the code example.

Note that you can only send emails from the verified domain. This means that the fields "From", "Source", "Sender", or "Return-Path" addresses must use the verified domain.

Example

This example is based on the AWS Java SMTP example. Notice the brc.mail.* entries, these are populated through system properties from the configuration file.

// returns info message or exception message
private String brcMail() throws MessagingException, UnsupportedEncodingException {
    // Replace [email protected] with your "From" address.
    // This address must be verified.
    final String FROM = "[email protected]";
    final String FROMNAME = "Customer";

    // Replace [email protected] with a "To" address. 
    final String TO = "[email protected]";

    // The port you will connect to on the Amazon SES SMTP endpoint.
    final int PORT = 587;

    final String SUBJECT = "BRC Test";

    final String BODY = String.join(
            System.getProperty("line.separator"),
            "<h1>BloomReach Cloud Email Test</h1>",
            "<p>This email was sent with BloomReach Cloud using the ",
            "<a href='https://github.com/javaee/javamail'>Javamail Package</a>",
            " for <a href='https://www.java.com'>Java</a>."
    );

    // Create a Properties object to contain connection configuration information.
    Properties props = System.getProperties();
    props.put("brc.mail.transport.protocol", "smtp");
    props.put("brc.mail.smtp.port", PORT);
    props.put("brc.mail.smtp.starttls.enable", "true");
    props.put("brc.mail.smtp.auth", "true");

    // Create a Session object to represent a mail session with the specified properties.
    Session session = Session.getDefaultInstance(props);

    // Create a message with the specified information.
    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(FROM, FROMNAME));
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
    msg.setSubject(SUBJECT);
    msg.setContent(BODY,"text/html");

    // Create a transport.
    Transport transport = session.getTransport();

    // Send the message
    String result;
    try
    {
        System.out.println("Sending...");

        // Connect to Amazon SES using the appConfigFile
        transport.connect(System.getProperty("brc.mail.smtp.host"),
                          System.getProperty("brc.mail.smtp.username"), 
                          System.getProperty("brc.mail.smtp.password"));

        // Send the email.
        transport.sendMessage(msg, msg.getAllRecipients());
        result = "Email sent!";
        System.out.println(result);
    }
    catch (Exception ex) {
        System.out.println("The email was not sent.");
        System.out.println("Error message: " + ex.getMessage());
        result = ex.getMessage();
    }
    finally
    {
        // Close and terminate the connection.
        transport.close();
    }
    return result;
}

Enterprise Forms

If you plan to use Enterprise forms, you also need to deploy the mail configuration file together with your distribution. It is critical to configure enterprise forms to use a sender email address that has been verified.
Note that using Enterprise forms will have an impact on the Blue/Green deployments; during the content freeze, data that is stored in the 'old' repository will get lost if you do not migrate the data to the new repository.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?