Email Campaign

Now are going to make analytics actionable and send an email campaign to all users, when they log out.

Enable Email channel

A channel represents the platform through which you engage your audience segment with messages. To engage your user segment with email campaigns and messages, enable the email channel in Amazon Pinpoint.

Email Settings in Amazon Pinpoint

Verify Email addresses

When you initially enable the email channel, your AWS account has access only to the email sandbox. With sandbox access, you can send 200 emails per 24-hour period at a maximum rate of one email per second. In addition, you can send email only to addresses that you verify.

Use these instructions to verify an email address.

Result will look similar to this:

Verify a new email address in Amazon Pinpoint

Check your inbox for a verification email and click on the link on the link provided to complete verification. If you did not receive the email, choose Send verification email again.

Tracking users

An endpoint can include attributes that define a user, which represents a person in your audience. For example, a user might represent someone who installed your mobile app, or someone who has an account on your website. You can add user attributes to track data that applies to an individual and doesn’t vary based on which device the person is using

address is a unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.

  1. Update React.useEffect() of AuthStateApp in src/App.js with this code:
React.useEffect(() => {
  onAuthUIStateChange((nextAuthState, authData) => {

    if (authData) {
      const { email, sub } = authData.attributes;
        address: email,
        channelType: 'EMAIL',
        optOut: 'NONE',
        userId: sub,
        userAttributes: {
          username: [authData.username]
}, []);

More details about all available parameters of Analytics.updateEndpoint() are available here.

  1. Publish Frontend code with Amplify CLI:
amplify publish

After build is deployed, login with any existing users in the app to update their endpoints with email attribute.

Create Segment

When you create a campaign, you choose a segment to send that campaign to. A segment is a group of your customers that share certain attributes. For example, a segment might contain all of your customers who use version 2.0 of your app on an Android device, or all customers who live in the city of Los Angeles. You can send multiple campaigns to a single segment, and you can send a single campaign to multiple segments.

We are going to a create a segment that includes all users and call it All Users:

  1. Open the Pinpoint Console.
  2. In the navigation page, choose Segments.
  3. Choose Create a segment.
  4. Set Name, e.g. All Users
  5. Choose Create segment.
Create a new segment in Amazon Pinpoint

More details about creating segments you can find on Building segments page of Amazon Pinpoint user guide.

Create Message template

A message template is a set of content and settings that you can create, save, and then reuse in messages that you send for any of your Amazon Pinpoint projects. When you create a template, you specify the content that you want to reuse in various components of messages that are based on the template.

These components are referred to as template parts. They can contain static text, personalized content, images, and other design elements, depending on the type of template.

To deliver dynamic, personalized content in messages that use a template, add message variables to the message template. A message variable is a placeholder that refers to a specific attribute that you or Amazon Pinpoint created to store information about your users. If a template contains message variables, Amazon Pinpoint replaces each variable with the current, corresponding value of the attribute for each recipient.

After the user endpoint was updated with username attribute, it becomes available as a Custom attribute. In Attribute finder section click Load custom attributes:

  1. Open the Pinpoint Console.
  2. In the navigation page, choose Message templates.
  3. Choose Create template.
  4. Under Channel, choose Email.
  5. Under Template details, set Template name, e.g. signout-template
  6. Under Email Details navigate to Attribute finder and Custom attributes, choose Load custom attributes.
Open Load custom attributes dialog for Message template
  1. Choose the project you are currently working on, e.g. traveldeals-dev. It will display custom attributed, that was recorded in Tracking Users.
  2. Choose Load custom attributes:
Select custom attributes for Message template
  1. Set Subject, e.g. {{User.UserAttributes.username}}, thank you for visiting us!
  2. Update Message with this code:
<!DOCTYPE html>
    <html lang="en">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
We are sorry to see you go!

Complete configuration will look like this:

Create a Message Template in Amazon Pinpoint

  1. Choose Create.

More details about creating templates you can find on Creating email templates page of Amazon Pinpoint user guide.

Create Email Campaign

A campaign is a messaging initiative that engages a specific audience segment. A campaign sends tailored messages according to a schedule that you define. You can use the console to create a campaign that sends messages through any single channel that is supported by Amazon Pinpoint: mobile push, email, or SMS.

Events may not be immediately available for selection. You can check Events if the event you are going to use became available, prior to moving to next section.
You can skip campaign creation process, move to next Lab, and come back to create email campaign in Pinpoint later.

  1. Open the Pinpoint Console.
  2. On the All projects page, choose the project that you want get data for, e.g. traveldeals-dev
  3. In the navigation page, choose Campaigns.
  4. Choose Create a campaign.
Step 1: Create a campaign
  1. Set Campaign name, e.g. Logout campaign
  2. Set Campaign type to Standard campaign.
  3. Set Channel to Email.
  4. Choose Next.
Create a Campaign in Amazon Pinpoint

More details available here.

Step 2: Choose a segment
  1. Choose Use an existing segment.
  2. Under Segment, choose a recently created segment, e.g. All Users
  3. Choose Next.

More details available here.

Select a segment for new Campaign
Step 3: Create your message
  1. Select Choose an existing email template.
  2. Use Choose a template, select a recently created template, e.g. signout-template:
  3. Choose Next.

More details available here.

Select a Message template for new Campaign
Step 4: Choose when to send the campaign
  1. Choose when the campaign should be sent: When an event occurs.
  2. Set Events to _userauth.sign_out
  3. Under Campaign dates, set Start date and time, e.g now + 15 minutes; and set End date and time, e.g. to 1 week from now.

The Start date and time that you choose has to be at least 15 minutes in the future.

  1. Choose your Time zone.
  2. Choose Next.

More details available here.

Choose when to send a new Campaign
Step 5: Review and launch
  1. Review settings.
  2. Choose Launch campaign.

More details available here.

Testing Campaign

Wait until Campaign changes status to In Progress. Then logout any user from the Web Application. You will receive an email like this:

Sample email sent to a user with Amazon Pinpoint

If you don’t receive email, when logging out a user, confirm that email associated with this user is verified, as described in Verify Email Addresses.