This topic describes how to integrate the EventBridge Service of Alibaba Cloud to send message notification of mail delivery results.
After you successfully configured the EventBridge, the delivery result of the mail sent by the DirectMail service will be sent to the specified event target (MNS, HTTP, etc.) according to the Event rules set in the EventBridge to realize asynchronous acquisition of the delivery result.
The following section describes how to complete Event Publishing settings.
EventBridge Service Activation
Search for the EventBridge on the AlibabaCloud homepage to activate the EventBridge service for free.
Create an Event Rule
Navigate to the Console, select Event Buses, then System Event Bus. To establish an event rule for the DirectMail service, initiate rule creation. Configure the essential details, inputting the rule name and description.
Configure the Event Pattern. The Event Source type is Alibaba Cloud Service Event Source. Selectacs.dm
, Event Type currently support Deliver Fail,Deliver Succeed,Trace Click,Trace Open. You can select Events Type as needed. Event Types that are not added will be filtered.
Configure the Event Targets and select the Service Type. Using the MNS message service as an example, designate the intended target queue for message dispatch. Detailed instructions for activating MNS and establishing a message receiving queue can be found under the topic "Activate MNS and Create a Queue for Receiving Messages.". By default, the Message Body is Complete Event and is not base64-encoded,Retry Policy and Dead-letter Queue can be set as needed. After setting, click Create.
After the rule is created, you can view it in the EventBridge overview.
Event Type And Modification Method
Supported event types
Deliver:Success
Deliver:Fail
Trace:Open
Trace:Click
Modify the statistics of various events
In the left-side navigation pane, click Event Rules-Edit Pattern-Event Type to modify the event type.
Prerequisites for Open or Click events
If you need to notify and distribute email opening and clicking events, the Recipient Tracking function shoulde be enabled in the early stage. For more information, see How Do I Enable The Data Tracking Feature?
Receive Event Publishing Messages And Verify That The Link Is Connected
Now we use the MNS event target set in the preceding procedure as an example to verify the Event Publishing link.
Activate MNS And Create A Queue for Receiving Messages
Get into MNS Console, if the MNS Service is not activated, follow the instructions to activate the MNS Service first.
Click Queues in the left-side navigation pane to go to the queues page.
Click Create Queue on the page. The create queue dialog box appears.
Enter the queue name (the queue name can be freely defined. We use
delivery-result-queue
as a case), other settings by default, and then click OK.
Trigger Event Publishing And View
After sending an email using the DriectMail, you can view the event tracking records in the EventBridge console;
View The Results of Event Publishing Targets
Open the MNS console and select the queue configured for the EventBridge in the queue list. click the Send messages button to jump to the send and receive message quick experience page;
Click the receive message button at the bottom of the page to view the event message. Click details to view the complete event message content. The Event id is consistent with the record in the EventBridge, and the event is successfully distributed to MNS;
Example of Setting Sending Address-level Event Publishing
The Event Publishing configured according to the preceding sample process takes effect on all sending domain names and addresses of the Driect Mail service. You can modify the JSON string of the event rule according to actual business requirements to distribute events based on filtering conditions such as sending addresses.
The following presents an illustration of designating 'batch@sg.example.top' as the sender address for email push events. Via the configuration of rules, this arrangement ensures that solely emails originating from 'batch@sg.example.top' have their notification disseminated to the event targets by the Event Bridge.
1. When creating an event rule, specify the specific content of the event pattern in the pattern content and filter the specified field content.
In this example, the schema is as follows:
{
"source": [
"acs.dm"
],
"type": [
"dm:Deliver:Fail",
"dm:Deliver:Succeed",
"dm:Trace:Click",
"dm:Trace:Open"
],
"data": {
"from": [
"batch@sg.example.top"
]
}
}
Here is a complete event message body. Based on the content and structure of the event body, see Event patterns, edit the schema content of the event rule.
All field names in the schema content must exist in the event body, otherwise the event message will be filtered.
The field names in the event mode must have the same nested structure as those in the event.
Event patterns are exactly matched character by character. Note the case. Strings are not standardized During matching.
The values to be matched follow the JSON rules: strings and numbers enclosed in quotation marks, and keywords true, false, and null without quotation marks.
The event pattern supports the semantics of OR, each Key in event pattern matching supports the semantics of AND, AND the Value of Key supports the semantics of array OR.
{
"datacontenttype": "application/json;charset=utf-8",
"aliyunaccountid": "1491110661959791",
"data": {
"rcpt": "example@example.com",
"deliver_time": "2024-05-22T08:27:42Z",
"err_code": "250",
"failed_type": "SendOk",
"env_id": "600000083914199845",
"send_time": "2024-05-22T08:27:41Z",
"err_msg": "250 Send Mail OK",
"header": {},
"from": "example2@alibabacloud.com",
"event": "dm:Deliver:Succeed",
"region": "*",
"msg_id": "d93a742c-adec-487d-8c39-98069c583760@alibaba.com",
"account": "example2@alibabacloud.com",
"status": 0
},
"subject": "acs:dm:*:1491110661959791:*",
"aliyunoriginalaccountid": "1491110661959791",
"source": "acs.dm",
"type": "dm:Deliver:Succeed",
"aliyunpublishtime": "2024-05-22T08:27:42.539Z",
"specversion": "1.0",
"aliyuneventbusname": "default",
"id": "1223c134-b66d-4d53-b05e-780c0261ce22",
"time": "2024-05-22T08:27:42.462Z ",
"Aliyunregionid": "ap-southeast-1"
}
2. Send an email through the batch@sg.example.top;
3. You can query this message in the MNS queue (This example uses MNS as the event target to receive event messages, and you can set the event target by yourself).
4. After sending a message using another sending address, the event details are queried in EventBridge-Event Tracking-Event Detail. However, the MNS side does not receive this event message, which means that the callback notification of the specified sending address is implemented.