FluentEmail Integration
Relevant source files
The following files were used as context for generating this wiki page:
The FluentEmail integration allows you to send emails using the FluentEmail .NET API with Resend as the underlying delivery service. This module provides a bridge between the standardized FluentEmail ISender interface and the specific Resend API client.
Sources: src/Resend.FluentEmail/README.md:1-12, src/Resend.FluentEmail/ResendSender.cs:13-17
Architecture and Components
The integration centers on the ResendSender class, which implements the FluentEmail ISender interface. It translates FluentEmail's internal IFluentEmail data structures into Resend-compatible EmailMessage objects.
Core Implementation
The ResendSender utilizes an instance of IResend to execute the actual API calls. When a user calls SendAsync on a FluentEmail object, the sender maps all fields—including recipients, headers, attachments, and tags—before forwarding the request to the Resend client.
Sources: src/Resend.FluentEmail/ResendSender.cs:13-36, src/Resend/EmailMessage.cs:8-102
The diagram above shows the relationship between the FluentEmail interface and the Resend implementation.
Sources: src/Resend.FluentEmail/ResendSender.cs:13-40
Data Mapping Logic
The integration performs deep mapping of email properties to ensure parity between the FluentEmail domain and the Resend API requirements.
Address Handling
The sender converts FluentEmail Address objects into Resend EmailAddress or EmailAddressList objects. It preserves both the email string and the optional display name for From, To, Cc, Bcc, and ReplyTo fields.
Sources: src/Resend.FluentEmail/ResendSender.cs:86-104, src/Resend.FluentEmail/ResendSender.cs:228-251
Priority and Headers
FluentEmail priorities are mapped to standard X-Priority headers since the Resend API accepts custom headers for mail delivery instructions.
| FluentEmail Priority | X-Priority Header | X-MSMail-Priority Header |
|---|---|---|
| High | 1 | High |
| Normal | (None) | (None) |
| Low | 5 | Low |
Sources: src/Resend.FluentEmail/ResendSender.cs:122-141
Body and Attachments
The logic supports both HTML and plaintext bodies. If IsHtml is true, the body is assigned to HtmlBody; otherwise, it goes to TextBody. Attachments are converted into EmailAttachment objects by copying the underlying stream data into byte arrays.
Sources: src/Resend.FluentEmail/ResendSender.cs:107-120, src/Resend.FluentEmail/ResendSender.cs:169-203
Configuration and Usage
To use the integration, you must register both the Resend client and the ResendSender in your application's dependency injection container.
Dependency Injection Setup
The following steps configure the service:
- Add Resend options with your API token.
- Register the
ResendClientas theIResendimplementation. - Register the
ResendSenderas the FluentEmailISender.
Sources: src/Resend.FluentEmail/README.md:38-51, README.md:43-50
The sequence diagram illustrates the flow from a FluentEmail method call to the final Resend API request.
Sources: src/Resend.FluentEmail/ResendSender.cs:38-60, tests/Resend.FluentEmail.Tests/FluentTests.cs:33-47
Implementation Example
Once configured, the integration allows sending emails using the FluentEmail builder pattern.
var email = Email
.From( "onboarding@resend.dev" )
.To( "delivered@resend.dev" )
.Subject( "Hello!" )
.Body( "<strong>Greetings<strong> 👋🏻", true );
email.Sender = _sender;
var response = await email.SendAsync();
Sources: src/Resend.FluentEmail/README.md:68-80, tests/Resend.FluentEmail.Tests/FluentTests.cs:33-47
Feature Support Matrix
The integration supports the following specific features provided by the Resend API:
| Feature | Supported | Implementation Detail |
|---|---|---|
| Display Names | Yes | Maps Address.Name to EmailAddress.DisplayName |
| HTML Body | Yes | Assigned to EmailMessage.HtmlBody |
| Plaintext | Yes | Assigned to EmailMessage.TextBody |
| Tags | Yes | Converts List<string> to List<EmailTag> with value "1" |
| Attachments | Yes | Reads Data stream into EmailAttachment.Content |
| CC/BCC | Yes | Supported for EmailAddressList |
Sources: src/Resend.FluentEmail/README.md:14-23, src/Resend.FluentEmail/ResendSender.cs:86-167
Summary
The FluentEmail integration provides a streamlined way to adopt Resend within existing .NET applications that use the FluentEmail library. By implementing the ISender interface, it abstracts the complexity of API-specific mapping, allowing developers to switch to Resend with minimal code changes while maintaining support for complex email features like attachments, headers, and custom tags.
Sources: src/Resend.FluentEmail/README.md:7-12, examples/README.md:1-15