Email Events & Logging
Relevant source files
The following files were used as context for generating this wiki page:
The Email Events & Logging systems manage custom event definitions and track API interaction history. Events enable developers to trigger specific workflows, while logging provides a technical audit trail for API requests and responses.
Event Management
The Events system manages the lifecycle of custom event definitions and their execution. You define events with names and optional JSON schemas to validate payloads.
Event Lifecycle and Operations
The IResend interface and ResendClient class provide methods to define, retrieve, and execute events.
- Create Event:
EventCreateAsyncregisters a new event name and its associated schema. - Retrieve Event:
EventRetrieveAsyncfetches event details by its unique identifier or its name. - List Events:
EventListAsyncreturns a paginated list of all defined events. - Send Event:
EventSendAsynctriggers an event using a specific contact or email address and an optional data payload.
Sources: src/Resend/IResend.cs:815-885, src/Resend/ResendClient.Events.cs:7-92
Event Data Structures
The SDK uses specific classes to represent event resources and execution requests.
| Class | Description |
|---|---|
EventResource | Represents the metadata of an event definition, including ID, Name, and Schema. |
EventSendData | Contains the parameters to trigger an event, including the event name, recipient identifiers, and payload. |
EventCreateData | Used to define a new event name and optional validation schema. |
Sources: src/Resend/EventResource.cs
Event Flow Architecture
The following diagram shows how an event is defined and subsequently triggered to interact with the Resend platform.
This diagram illustrates the separation between defining an event structure and executing a specific event instance. Sources: src/Resend/ResendClient.Events.cs:7-92, src/Resend/IResend.cs:815-885
Email Webhook Events
When Resend delivers notifications via webhooks, it provides detailed metadata about email lifecycle events. The EmailEventData class structures this information for consumption.
Lifecycle Status Data
Email events include specific status data based on the nature of the event:
- Click Data: Captures IP address, link URL, timestamp, and user agent when a recipient clicks a link.
- Open Data: Captures IP address and timestamp when an email is opened.
- Bounce Data: Includes diagnostic codes and bounce types (e.g., permanent or transient).
- Suppression Data: Indicates if an email was blocked due to previous bounces or complaints.
Sources: src/Resend.Webhooks/EmailEventData.cs:126-215
Recipient and Header Information
Webhook event payloads include full context of the original message to assist with tracking and reconciliation.
| Field | Type | Description |
|---|---|---|
EmailId | Guid | Unique identifier of the specific email. |
MessageId | string | RFC Message-ID header value. |
To/Cc/Bcc | EmailAddressList | Lists of recipients involved in the event. |
Headers | List | Custom headers included in the original email. |
Tags | Dictionary | Metadata tags attached to the message. |
Sources: src/Resend.Webhooks/EmailEventData.cs:11-75
API Request Logging
The Logging system provides visibility into the interactions between the SDK and the Resend API. It records request details and response statuses.
Log Retrieval
You can access API logs through two primary methods:
- List Logs:
LogListAsyncretrieves a paginated summary of recent API requests. - Retrieve Log:
LogRetrieveAsyncfetches the full details of a specific request, including body content if available.
Sources: src/Resend/IResend.cs:1033-1049
Log Data Model
The Log class contains the technical details of an API transaction.
This diagram represents the structure of an API log entry used for auditing and debugging. Sources: src/Resend/IResend.cs:1033-1049, src/Resend/Log.cs
Event Pagination
Event listings support standard pagination to handle large volumes of definitions.
| Parameter | Type | Description |
|---|---|---|
Limit | int? | Number of records to return per page. |
After | string | Cursor for forward pagination. |
Before | string | Cursor for backward pagination. |
Sources: src/Resend/ResendClient.Events.cs:46-70
Summary
The Email Events & Logging system facilitates both proactive automation and reactive auditing. Developers use the Events module to define custom triggers for business workflows, while the Webhook and Logging modules provide data for tracking email delivery performance and SDK behavior. All event and log operations are performed asynchronously through the ResendClient.