コンテンツにスキップ

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.