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. In the left-side navigation pane, click Event Buses.
  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the custom event bus that you want to manage.
  3. In the left-side navigation pane, click Event Sources, and then click Add Event Source.
  4. In the Add Custom Event Source panel, set the Name and Description parameters, select Custom Application from the Event Provider drop-down list, and then click OK.

Step 2: Create an event rule

Important 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. In the left-side navigation pane, click Event Buses.
  2. In the top navigation bar, select a region. On the Event Buses page, click the name of the event bus that you want to manage.
  3. In the left-side navigation pane, click Event Rules. On the page that appears, click Create Rule.
  4. Perform the following operations in the Create Rule panel:
    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 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 and click Create.
      Note You can configure up to five event targets for an event rule.
      • Service Type: Select 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 Fixed Value or Template.
        • If you click Fixed Value, enter the recipient information similar to the following example:
          alice@example.com
        • If you click Template, 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 parameters in the template.

        The following part shows sample parameters and a sample template:

        Sample parameters:

        {
          "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, click Event Buses.
  3. In the top navigation bar, select a region.
  4. On the Event Buses page, 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, select a custom event source from the Custom Event Source drop-down list, enter the event content in the Event Body code editor, and then 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 successfully, 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
    Trends in sending emails
    Figure 2. Example: statistics about the emails sent over the last seven days
    Statistics about the emails sent over the last seven days