# Mailpit Integration

Test email sending locally using Mailpit with .NET Aspire.

- Repository: https://github.com/Aaronontheweb/dotnet-skills (1244 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-10-28
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add Aaronontheweb/dotnet-skills --skill mailpit-integration -g -a claude-code -y`
Codex: `npx skills add Aaronontheweb/dotnet-skills --skill mailpit-integration -g -a codex -y`
Cursor: `npx skills add Aaronontheweb/dotnet-skills --skill mailpit-integration -g -a cursor -y`
Gemini CLI: `npx skills add Aaronontheweb/dotnet-skills --skill mailpit-integration -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add Aaronontheweb/dotnet-skills`

## Description

Test email sending locally using Mailpit with .NET Aspire. Captures all outgoing emails without sending them. View rendered HTML, inspect headers, and verify delivery in integration tests.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Email Testing with Mailpit and .NET Aspire

## When to Use This Skill

Use this skill when:
- Testing email delivery locally without sending real emails
- Setting up email infrastructure in .NET Aspire
- Writing integration tests that verify emails are sent
- Debugging email rendering and headers

**Related skills:**
- `aspnetcore/mjml-email-templates` - MJML template authoring
- `testing/verify-email-snapshots` - Snapshot test rendered HTML
- `aspire/integration-testing` - General Aspire testing patterns

---

## What is Mailpit?

[Mailpit](https://github.com/axllent/mailpit) is a lightweight email testing tool that:
- Captures all SMTP traffic without delivering emails
- Provides a web UI to view captured emails
- Exposes an API for programmatic access
- Supports HTML rendering, headers, and attachments

Perfect for development and integration testing.

---

## Aspire AppHost Configuration

Add Mailpit as a container in your AppHost:

```csharp
// AppHost/Program.cs
var builder = DistributedApplication.CreateBuilder(args);

// Add Mailpit for email testing
var mailpit = builder.AddContainer("mailpit", "axllent/mailpit")
    .WithHttpEndpoint(port: 8025, targetPort: 8025, name: "ui")
    .WithEndpoint(port: 1025, targetPort: 1025, name: "smtp");

// Reference in your API project
var api = builder.AddProject<Projects.MyApp_Api>("api")
    .WithReference(mailpit.GetEndpoint("smtp"))
    .WithEnvironment("Smtp__Host", mailpit.GetEndpoint("smtp"));

builder.Build().Run();
```

---

## SMTP Configuration

### appsettings.json

```json
{
  "Smtp": {
    "Host": "localhost",
    "Port": 1025,
    "EnableSsl": false,
    "FromAddress": "noreply@myapp.com",
    "FromName": "MyApp"
  }
}
```

### Configuration Class

The rest: https://github.com/Aaronontheweb/dotnet-skills/blob/HEAD/skills/aspire-mailpit-integration/SKILL.md
