| title | Handle Email events |
|---|---|
| titleSuffix | Azure Communication Services |
| description | This article describes how to handle Azure Communication Services events. See how to create, receive, and subscribe to Email delivery report and Email engagement tracking events. |
| author | anmolbohra |
| manager | komivi.agbakpem |
| services | azure-communication-services |
| ms.author | anmolbohra |
| ms.date | 03/31/2023 |
| ms.topic | quickstart |
| ms.service | azure-communication-services |
| ms.subservice | |
| ms.custom | sfi-image-nochange |
Get started with Azure Communication Services by using Azure Event Grid to handle Communication Services Email events. After subscribing to Email events such as delivery reports and engagement reports, you generate and receive these events. Completing this quickstart incurs a small cost of a few USD cents or less in your Azure account.
- An Azure account with an active subscription. Create an account for free.
- A Communication Services resource. For detailed information, see Create an Azure Communication Services resource.
- An Email resource with a provisioned domain. Create an Email Resource.
Event Grid is a cloud-based eventing service. This article describes how to subscribe to communication service events, and trigger an event to view the result. Typically, you send events to an endpoint that processes the event data and takes actions. In this article, we send the events to a web app that collects and displays the messages.
To set up the environment that we use to generate and receive events, complete the steps in the following sections.
If you have yet to use Event Grid in your Azure subscription, you might need to register your Event Grid resource provider. To register the provider, follow these steps:
- Go to the Azure portal.
- On the left menu, select Subscriptions.
- Select the subscription that you use for Event Grid.
- On the left menu, under Settings, select Resource providers.
- Find Microsoft.EventGrid.
- If your resource provider isn't registered, select Register.
It might take a moment for the registration to finish. Select Refresh to update the status. When Registered appears under Status, you're ready to continue.
For this quickstart, we use an Event Grid viewer to view events in near-real time. The viewer provides the user with the experience of a real-time feed. Also, the payload of each event should be available for inspection.
To set up the viewer, follow the steps in Azure Event Grid Viewer.
You can subscribe to specific events to provide Event Grid with information about where to send the events that you want to track.
-
In the portal, go to the Communication Services resource that you created.
-
Inside the Communication Services resource, on the left menu of the Communication Services page, select Events.
-
Select Add Event Subscription.
:::image type="content" source="./media/handle-email-events/select-events.png" alt-text="Screenshot that shows the Events page of an Azure Communication Services resource. The Event Subscription button is called out.":::
-
On the Create Event Subscription page, enter a name for the event subscription.
-
Under Event Types, select the events that you'd like to subscribe to. For Email, you can choose
Email Delivery Report ReceivedandEmail Engagement Tracking Report Received. -
If prompted to provide a System Topic Name, feel free to provide a unique string. This field has no impact on your experience and is used for internal telemetry purposes.
:::image type="content" source="./media/handle-email-events/select-events-create-eventsub.png" alt-text="Screenshot that shows the Create Event Subscription dialog. Under Event Types, Email Delivery Report Received and Email Engagement Tracking Report Received are selected.":::
-
For Endpoint type, select Web Hook.
:::image type="content" source="./media/handle-email-events/select-events-create-linkwebhook.png" alt-text="Screenshot that shows a detail of the Create Event Subscription dialog. In the Endpoint Type list, Web Hook is selected.":::
-
For Endpoint, select Select an endpoint, and then enter the URL of your web app.
In this case, we use the URL from the Event Grid viewer that we set up earlier in the quickstart. The URL for the sample has this format:
https://{{site-name}}.azurewebsites.net/api/updates -
Select Confirm Selection.
:::image type="content" source="./media/handle-email-events/select-events-create-selectwebhook-epadd.png" alt-text="Screenshot that shows the Select Web Hook dialog. The Subscriber Endpoint box contains a URL, and a Confirm Selection button is visible.":::
To generate and receive Email events, take the steps in the following sections.
To view event triggers, we need to generate some events. To trigger an event, send email using the Email domain resource attached to the Communication Services resource.
-
Email Delivery Report Receivedevents are generated when the Email status is in terminal state, like Delivered, Failed, FilteredSpam, Quarantined. -
Email Engagement Tracking Report Receivedevents are generated when the email sent is either opened or a link within the email is clicked. To trigger an event, you need to turn on theUser Interaction Trackingoption on the Email domain resource
Check out the full list of events that Communication Services supports.
After you generate an event, notice that Email Delivery Report Received and Email Engagement Tracking Report Received events are sent to your endpoint. These events show up in the Event Grid viewer that we set up at the beginning of this quickstart. Select the eye icon next to the event to see the entire payload. Events should look similar to the following data:
:::image type="content" source="./media/handle-email-events/email-delivery-report-received.png" alt-text="Screenshot of the Azure Event Grid viewer that shows the Event Grid schema for an EMAIL delivery report received event.":::
:::image type="content" source="./media/handle-email-events/email-engagementtracking-report-received.png" alt-text="Screenshot of the Azure Event Grid viewer that shows the Event Grid schema for an EMAIL engagement tracking report event.":::
EngagementContextrefers to the link clicked when the engagementType isClick.UserAgentrefers to the User-Agent from which this email engagement event originated. For example, if the user interacted on Microsoft Edge using a Win10 machine: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246EngagementTyperefers to the type of engagement. Possible values areVieworClick.Recipientrefers to the recipient who engaged with the email. Note that this field is empty when the original email was sent to multiple recipients at a time.
For more information, see event schemas and other eventing concepts.
If you want to clean up and remove a Communication Services subscription, you can delete the resource or resource group. Deleting the resource group also deletes any other resources associated with it. Learn more about cleaning up resources.
In this quickstart, you learned how to consume Email events. You can receive Email events by creating an Event Grid subscription.
[!div class="nextstepaction"] Send Email
For schema information and example events, see Azure Communication Services - Email events.