Gå til indhold

Mailpit Hosting integration reference

Dette indhold er ikke tilgængeligt i dit sprog endnu.

⭐ 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 — Tilføj CommunityToolkit.Aspire.Hosting.MailPit-pakke
aspire add communitytoolkit-mailpit

Aspire CLI er interaktiv; vælg det passende søgeresultat når du bliver spurgt:

Aspire CLI — Eksempel output
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.