You can use event rules to filter events and route events to Direct Mail. This topic describes the prerequisites and procedure for routing custom events to Direct Mail. This topic also describes how to verify the result.

Step 1: Create a custom event source

  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, choose Event-driven Operations > Event Sources.
  3. In the top navigation bar, select a region.
  4. On the Event Sources page, click the Custom Event Sources tab. On the Custom Event Sources tab, click Add Event Source.
  5. In the Add Custom Event Source panel, enter a name and a description, select an event provider, click Create Custom Event Bus, enter the name of a new custom event bus, and then click OK.

Step 2: Create an event rule

Notice The event targets that you want to configure for an event rule must reside in the same region as the event rule.
  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, choose Event-driven Operations > Event Rules.
  3. In the top navigation bar, select a region.
  4. On the Event Rules page, select the custom event bus and click Create Rule.
  5. On the Create Rule page, perform the following steps:
    1. In the Configure Basic Info step, enter a rule name in the Name field and a rule description in the Description field, and click Next Step.
    2. In the Configure Event Pattern step, set the Event Source Type parameter to Custom Event Source, select the custom event source that is created in Step 1 from the Event Source drop-down list, specify an event pattern in the Event Pattern Content code editor, and then click Next Step.

      For more information, see Event patterns.

    3. In the Configure Targets step, configure an event target. Then, click Create.
      Note You can configure a maximum of five event targets for an event rule.
      • Service Type: Click Email.
      • Subject: Enter the subject of the email.
      • Sender Address: Enter the sender address that you created in the Direct Mail console.
      • Address Type: Click Random Account or Sender Address.
      • Return Address: Click Yes or No.
      • Recipient: Click Constant or Partial Event.
        • If you click Constant, enter the recipient information similar to the following example:
          alice@example.com
        • If you click Partial Event, enter the recipient information similar to the following example:
          $.data.addr
        Note Separate multiple email addresses with commas (,). You can enter a maximum of 100 email addresses.
      • HTML Body: Click Yes or No.
        • Yes: The email body is of the HTML type.
        • No: The email body is of the text type.
      • Body: Specify a template. Events are routed in the format that is defined in a custom template to event targets. You can customize variables in the template.

        The following part shows sample variables and a sample template:

        Sample variables:

        {
          "source":"$.source",
          "type":"$.type"
        }

        Sample template:

        An error was sent from ${source},caused by ${type}.

        For more information, see Event transformation.

Step 3: Publish an event

  1. Log on to the EventBridge console.
  2. In the left-side navigation pane, choose Event-driven Operations > Event Buses.
  3. In the top navigation bar, select a region.
  4. In the Custom Event Buses section, find the event bus to which you want to publish an event and click Publish Event in the Operations column.
    Note You can publish events only to custom event buses in the EventBridge console.
  5. In the Publish Event to Custom Event Bus panel, enter the event content in the code editor and click OK.
    For more information about the event parameters, see Overview.

Verify the result

You can check whether the event is received in the Direct Mail console.

  1. Log on to the Direct Mail console.
  2. In the top navigation bar, select a region.
  3. In the left-side navigation pane, choose Reporting > Delivery Overview.
  4. On the Delivery Reports page, set the Email Tag, Sender Address, From: (UTC+8), and To: (UTC+8) parameters. Then, click Query.

    You can view the number of emails sent over the last seven days, the number of emails that are sent, the number of emails that fail to be sent, the number of invalid email addresses, the success rate of sent emails, and the rate of invalid email addresses.

    Figure 1. Example: trends in sending emails
    Example: trends in sending emails
    Figure 2. Example: statistics about the emails sent over the last seven days
    Example: statistics about the emails sent over the last seven days