Prerequisites
To get the most out of this guide, you’ll need to:1. Install
2. Send emails using HTML
In the startup of your application, configure the DI container as follows:IEmailr instance:
Learn how to send your first email using the Emailr .NET SDK.
dotnet add package Emailr
using Emailr;
builder.Services.AddOptions();
builder.Services.AddHttpClient<EmailrClient>();
builder.Services.Configure<EmailrClientOptions>( o =>
{
o.ApiToken = Environment.GetEnvironmentVariable( "EMAILR_APITOKEN" )!;
} );
builder.Services.AddTransient<IEmailr, EmailrClient>();
IEmailr instance:
using Emailr;
public class FeatureImplementation
{
private readonly IEmailr _emailr;
public FeatureImplementation( IEmailr emailr )
{
_emailr = emailr;
}
public Task Execute()
{
var message = new EmailMessage();
message.From = "Acme <[email protected]>";
message.To.Add( "[email protected]" );
message.Subject = "hello world";
message.HtmlBody = "<strong>it works!</strong>";
await _emailr.EmailSendAsync( message );
}
}