Перейти до вмісту

Mailpit Hosting integration reference

Цей контент ще не доступний вашою мовою.

⭐ Community Toolkit Mailpit logo

To get started with the Aspire Mailpit integrations, follow the Get started with Mailpit integrations guide.

This article includes full details about the Aspire Mailpit Hosting integration.

To access the Mailpit hosting integration APIs for expressing Mailpit resources in your AppHost project, install the 📦 CommunityToolkit.Aspire.Hosting.MailPit NuGet package:

Aspire CLI — Додати пакет CommunityToolkit.Aspire.Hosting.MailPit
aspire add communitytoolkit-mailpit

Aspire CLI інтерактивний; оберіть відповідний результат пошуку:

Aspire CLI — Приклад виводу
Select an integration to add:
> communitytoolkit-mailpit (CommunityToolkit.Aspire.Hosting.MailPit)
> Other results listed as selectable options...

To add Mailpit to your app host, use the AddMailPit extension method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var mailpit = builder.AddMailPit("mailpit");
builder.AddProject<Projects.ExampleProject>()
.WithReference(mailpit);
// After adding all resources, run the app...

When Aspire adds Mailpit to the app host, it creates a new Mailpit instance with the docker.io/axllent/mailpit container image.

Mailpit exposes two ports:

  • SMTP port: 1025 (for sending emails)
  • Web UI port: 8025 (for viewing emails in the browser)

Both ports are automatically configured and accessible through the Aspire dashboard.

To persist emails across container restarts, use the WithDataVolume method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var mailpit = builder.AddMailPit("mailpit")
.WithDataVolume();
builder.AddProject<Projects.ExampleProject>()
.WithReference(mailpit);

The data volume is used to persist the Mailpit data outside the lifecycle of the container.

For development scenarios, you may want to use bind mounts instead of data volumes. To add a data bind mount, call the WithDataBindMount method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var mailpit = builder.AddMailPit("mailpit")
.WithDataBindMount(source: @"C:\Mailpit\Data");
builder.AddProject<Projects.ExampleProject>()
.WithReference(mailpit);

The Mailpit web interface is automatically available when you add a Mailpit resource. You can access it through the Aspire dashboard by clicking on the endpoint for the Mailpit resource.