Email Templates Management
Relevant source files
The following files were used as context for generating this wiki page:
Email Templates Management provides the infrastructure for creating, maintaining, and utilizing hosted email layouts within the Resend ecosystem. This system allows you to separate email design from application logic by storing HTML and text content on Resend's servers. You can then reference these templates by identifier or alias when sending messages, providing dynamic content through variable substitution.
The management suite supports a full lifecycle including draft creation, versioning, publishing, and duplication. When you send an email using a template, the system automatically resolves variables and applies default settings like the sender address or subject line if defined in the template.
Data Models and Architecture
The template system utilizes three primary models to manage data at different stages of the lifecycle. The Template class serves as the comprehensive model containing the full body content and metadata. The TemplateSummary provides a lightweight version used for listing multiple templates without the overhead of the HTML/Text bodies. Finally, the EmailMessageTemplate carries the specific instructions for using a template during an email transmission.
The diagram shows the relationship between the full Template definition, its summary representation, and the message-time reference.
Sources: src/Resend/Template.cs:6-85, src/Resend/TemplateSummary.cs:5-46, src/Resend/EmailMessageTemplate.cs:5-24
Template Fields and Constraints
| Field | Type | Description |
|---|---|---|
Id | Guid | Unique identifier for the template. |
Name | string | Display name of the template. |
Alias | string? | Optional human-readable unique identifier. |
Status | TemplateStatus | Current lifecycle state (e.g., Draft, Published). |
HtmlBody | string | The HTML content of the template. |
TextBody | string | The plain text version of the template. |
Variables | List | A list of placeholders for dynamic content. |
Sources: src/Resend/Template.cs:9-85
Template Operations
The ResendClient implements the IResend interface to provide methods for template lifecycle management. These operations allow you to manage templates using either their Guid identifier or their unique string Alias.
The lifecycle flow illustrates how a template moves from initial creation to publication and duplication.
Sources: src/Resend/ResendClient.Templates.cs:40-112, src/Resend/IResend.cs:575-655
API Methods Summary
- List:
TemplateListAsyncretrieves a paginated list ofTemplateSummaryobjects. - Create:
TemplateCreateAsyncinitializes a new template and returns itsGuid. - Retrieve:
TemplateRetrieveAsyncfetches the fullTemplateobject including bodies. - Update:
TemplateUpdateAsyncmodifies existing template properties or content. - Publish:
TemplatePublishAsyncmakes a specific version of the template active for sending. - Duplicate:
TemplateDuplicateAsynccreates a new template based on an existing one. - Delete:
TemplateDeleteAsyncpermanently removes the template from the system.
Sources: src/Resend/ResendClient.Templates.cs:1-113, src/Resend/IResend.cs:567-656
Integration with Email Sending
Templates are integrated into the EmailMessage class via the Template property. When you provide a Template object in a send request, it is mutually exclusive with setting HtmlBody or TextBody directly.
The sequence demonstrates the interaction when sending an email using a hosted template.
Sources: src/Resend/EmailMessage.cs:88-96, src/Resend/IResend.cs:27-37
Template Application Logic
When you send a templated email, you use the EmailMessageTemplate class to specify:
- Name: The identifier or alias of the hosted template to use.
- Variables: A dictionary where keys represent template placeholders and values represent the replacement data.
If the hosted template defines a default From address or Subject, you can omit these fields in the EmailMessage object. The Resend API will populate them from the template definition during transmission.
Sources: src/Resend/EmailMessageTemplate.cs:5-24, src/Resend/EmailMessage.cs:17-37
Conclusion
Email Templates Management in the Resend .NET SDK provides a robust way to manage hosted email content. By utilizing Template, TemplateSummary, and EmailMessageTemplate, the system ensures efficient data handling between designing layouts and executing delivery. The support for both unique identifiers and human-readable aliases across all CRUD and lifecycle operations allows for flexible integration into various application workflows.
Sources: src/Resend/Template.cs, src/Resend/ResendClient.Templates.cs, src/Resend/EmailMessageTemplate.cs