Table of Contents

Class TwilioMailService

Namespace
NuvTools.Notification.Mail.Twilio
Assembly
NuvTools.Notification.Mail.Twilio.dll

Twilio Email API implementation of IMailService.

public class TwilioMailService : IMailService
Inheritance
TwilioMailService
Implements
Inherited Members

Remarks

This service posts messages to the Twilio Email endpoint (POST /v1/Emails), which processes requests asynchronously and answers with 202 Accepted plus an operation identifier. It supports HTML and plain text content, Base64 attachments, inline images, custom headers, tags, Liquid personalization variables and scheduled delivery. Register it through AddTwilioMail(IServiceCollection, IConfiguration, string, Action<HttpStandardResilienceOptions>?).

Constructors

TwilioMailService(HttpClient, IOptions<TwilioMailConfigurationSection>)

Twilio Email API implementation of IMailService.

public TwilioMailService(HttpClient httpClient, IOptions<TwilioMailConfigurationSection> appMailConfiguration)

Parameters

httpClient HttpClient

The typed client configured with the API base address and Basic authentication.

appMailConfiguration IOptions<TwilioMailConfigurationSection>

The mail configuration options containing the Twilio credentials and defaults.

Remarks

This service posts messages to the Twilio Email endpoint (POST /v1/Emails), which processes requests asynchronously and answers with 202 Accepted plus an operation identifier. It supports HTML and plain text content, Base64 attachments, inline images, custom headers, tags, Liquid personalization variables and scheduled delivery. Register it through AddTwilioMail(IServiceCollection, IConfiguration, string, Action<HttpStandardResilienceOptions>?).

Fields

EmailsEndpoint

Relative path of the Twilio Email send endpoint.

public const string EmailsEndpoint = "v1/Emails"

Field Value

string

MaxRequestSizeInBytes

Maximum request size accepted by the Twilio Email API, including attachments.

public const int MaxRequestSizeInBytes = 10485760

Field Value

int

Methods

SendAsync(MailMessage, CancellationToken)

Sends an email message asynchronously using the Twilio Email API.

public Task<MailSendResult> SendAsync(MailMessage mailMessage, CancellationToken cancellationToken = default)

Parameters

mailMessage MailMessage

The mail message to send, including sender, recipients, subject, body, and optional attachments.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<MailSendResult>

The identifier of the asynchronous operation created by the API, along with the URL to track it.

Remarks

The returned result means the request was accepted for processing. The delivery status can be tracked through TrackingLocation.

Exceptions

TwilioMailException

Thrown when the API rejects the request or answers unexpectedly.