![]() |
VOOZH | about |
dotnet add package TPJ.Email --version 10.0.0
NuGet\Install-Package TPJ.Email -Version 10.0.0
<PackageReference Include="TPJ.Email" Version="10.0.0" />
<PackageVersion Include="TPJ.Email" Version="10.0.0" />Directory.Packages.props
<PackageReference Include="TPJ.Email" />Project file
paket add TPJ.Email --version 10.0.0
#r "nuget: TPJ.Email, 10.0.0"
#:package TPJ.Email@10.0.0
#addin nuget:?package=TPJ.Email&version=10.0.0Install as a Cake Addin
#tool nuget:?package=TPJ.Email&version=10.0.0Install as a Cake Tool
Simple SMTP email library for .NET that supports HTML emails, attachments, single sends, and batch sends.
dotnet add package TPJ.Email
Add your SMTP settings to appsettings.json.
{
"TPJ": {
"Email": {
"SmtpClient": "smtp.example.com",
"SmtpUser": "smtp-user",
"SmtpPassword": "smtp-password",
"From": "no-reply@example.com",
"FromDisplayName": "My App",
"Port": 587,
"EnableSSL": true,
"Debug": false
}
}
}
Supported settings:
SmtpClientSmtpUserSmtpPasswordFromFromDisplayNamePortEnableSSLDebugSmtpClient, SmtpUser, and SmtpPassword can also be loaded from Azure Key Vault by using:
TPJ:Email:AzureKeyVault:SmtpClientTPJ:Email:AzureKeyVault:SmtpUserTPJ:Email:AzureKeyVault:SmtpPasswordRegister IEmailSettings from configuration, then add the email services.
using TPJ.Email;
builder.Services.AddTPJEmail();
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TPJ.Email;
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.Build();
var services = new ServiceCollection();
services.AddTPJEmail();
using var serviceProvider = services.BuildServiceProvider();
var emailer = serviceProvider.GetRequiredService<IEmailer>();
await emailer.SendAsync(new CreateEmailSingle
{
To =
[
new CreateEmailAudience
{
Email = "jane@example.com",
DisplayName = "Jane"
}
],
Subject = "Hello from a console app",
Body = "<h1>Email sent from TPJ.Email</h1><p>This email was sent from a console application.</p>"
});
Example with a minimal API:
using TPJ.Email;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<IEmailSettings>(_ => new EmailSettings(builder.Configuration));
builder.Services.AddTPJEmail();
var app = builder.Build();
app.MapPost("/emails/test", async (string to, IEmailer emailer, CancellationToken cancellationToken) =>
{
await emailer.SendAsync(new CreateEmailSingle
{
To =
[
new CreateEmailAudience
{
Email = to
}
],
Subject = "Hello from the API",
Body = "<p>This email was sent from an ASP.NET Core API.</p>"
}, cancellationToken);
return Results.Accepted();
});
app.Run();
Use SendBatchAsync when you want to send the same base email to multiple recipients, with optional per-recipient subject or body overrides.
await emailer.SendBatchAsync(new CreateEmailBatch
{
From = new CreateEmailAudience
{
Email = "no-reply@example.com",
DisplayName = "My App"
},
Subject = "Weekly update",
Body = "<p>Default email body</p>",
Emails =
[
new CreateEmailEmail
{
To =
[
new CreateEmailAudience { Email = "alice@example.com", DisplayName = "Alice" }
]
},
new CreateEmailEmail
{
To =
[
new CreateEmailAudience { Email = "bob@example.com", DisplayName = "Bob" }
],
Subject = "Weekly update for Bob",
Body = "<p>Custom body for Bob</p>"
}
]
});
Attachments can be added by file path or byte array.
await emailer.SendAsync(new CreateEmailSingle
{
To =
[
new CreateEmailAudience { Email = "jane@example.com" }
],
Subject = "Report",
Body = "<p>Please find the report attached.</p>",
Attachments =
[
new CreateEmailAttachment
{
FilePath = "Reports/report.pdf"
}
]
});
From is omitted on the email request, the configured TPJ:Email:From value is used.CreateEmailEmail in a batch is sent separately.To must contain at least one valid email address.| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on TPJ.Email:
| Package | Downloads |
|---|---|
|
TPJ.Logging
Simple error logging library that can send emails and/or log to a txt file |
This package is not used by any popular GitHub repositories.
V10.0.0 now runs on .NET 10 with significant changes to how emails are sent see README.md for details