Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

MailKite

MailKite for ASP.NET Core

Email for every product you ship — send over a verified domain, receive email as a webhook, give an AI agent its own inbox.
The official MailKite IEmailSender for ASP.NET Core Identity.

Docs · Library guide · mailkite.dev · AI agents

nuget

Not yet published. This package lives in the MailKite monorepo (integrations/aspnet-core/) and has not been released to NuGet yet — see docs/integrations/aspnet-core.md ## Releasing for the honest current state. This README describes the package as it will work once shipped.

Install

dotnet add package MailKite.AspNetCore

Targets net8.0 — the minimum ASP.NET Core version that ships Identity's generic IEmailSender<TUser> (used by MapIdentityApi<TUser>()). Depends on the MailKite SDK and Microsoft.AspNetCore.Identity.UI (for the classic, non-generic IEmailSender).

What / why

ASP.NET Core Identity defines IEmailSender (scaffolded Razor Pages UI: dotnet new webapp -au Individual) and, since .NET 8, the generic IEmailSender<TUser> (minimal-API Identity: MapIdentityApi<TUser>()) specifically so account-confirmation and password-reset mail can be swapped in with one interface implementation — the same "swap one interface" wedge as Laravel's Mail::extend and Rails's ActionMailer::Base.add_delivery_method. Without a first-party adapter, a .NET dev integrating MailKite has to hand-wire the .NET SDK into every Identity email hook. This package makes MailKite Identity's email sender: install, set an API key + a from address, and every confirmation/reset email goes out through POST /v1/send via the official MailKite .NET SDK (MailKite, sdks/dotnet) — SDK-first per docs/CODE-SAMPLES.md, never raw HTTP.

Quickstart

Program.cs:

using MailKite.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMailKiteEmailSender(builder.Configuration, options =>
{
    options.FromAddress = "hello@yourdomain.com";
    options.FromName = "Your App";
    // ApiKey falls back to the MAILKITE_API_KEY environment variable if left unset here.
});

// ... AddDbContext, AddIdentity/AddIdentityApiEndpoints, etc.

var app = builder.Build();

.env / environment:

MAILKITE_API_KEY=mk_live_...

That's it — AddMailKiteEmailSender registers both:

  • IEmailSender (Microsoft.AspNetCore.Identity.UI.Services) for the scaffolded Identity Razor Pages UI (Areas/Identity/...), and
  • IEmailSender<TUser> (Microsoft.AspNetCore.Identity) for MapIdentityApi<TUser>()

against the same MailKiteClient and MailKiteEmailSenderOptions, so whichever Identity flavor the app uses just works.

Configuration

MailKiteEmailSenderOptions resolves, in order: the configure delegate passed to AddMailKiteEmailSender, then the "MailKite" section of IConfiguration (if a configuration was passed), then the MAILKITE_API_KEY environment variable for ApiKey.

Option Required Notes
ApiKey Yes (or env var) A MailKite API key (mk_live_…). Falls back to MAILKITE_API_KEY.
FromAddress Yes Verified sending domain address — IEmailSender's methods carry no sender, so it's configured once here.
FromName No Display name paired with FromAddress.
BaseUrl No Override the API base URL (defaults to https://api.mailkite.dev).

appsettings.json equivalent:

{
  "MailKite": {
    "FromAddress": "hello@yourdomain.com",
    "FromName": "Your App"
  }
}

(Keep ApiKey out of appsettings.json — set it via MAILKITE_API_KEY or user-secrets/Key Vault in production.)

Two ways to register: without configuration binding

builder.Services.AddMailKiteEmailSender(options =>
{
    options.ApiKey = "mk_live_...";       // or leave unset to use MAILKITE_API_KEY
    options.FromAddress = "hello@yourdomain.com";
});

What maps where

ASP.NET Core Identity MailKite send
IEmailSender.SendEmailAsync(email, subject, htmlMessage) to, subject, html
IEmailSender<TUser>.SendConfirmationLinkAsync subject "Confirm your email", html = a link
IEmailSender<TUser>.SendPasswordResetLinkAsync subject "Reset your password", html = a link
IEmailSender<TUser>.SendPasswordResetCodeAsync subject "Reset your password", html = the code
MailKiteEmailSenderOptions.FromAddress/FromName from (both non-generic and generic senders share the same configured from)

Honest failures, not silent drops. MailKiteClient.Send throws MailKiteException (with the API's own error message + HTTP status) on any non-2xx response — an unverified from domain, a suppressed recipient, or a rate limit surfaces to the caller instead of pretending the email went out.

Starter app

A runnable demo wiring this package into real ASP.NET Core Identity (register, confirm email, forgot password) lives in starters/aspnet-coredotnet run instructions there.

All MailKite libraries

Same contract, every language (full list: https://mailkite.dev/docs/libraries):

Library Repo Distribution
MailKite for .NET mailkite-dotnet NuGet
MailKite for ASP.NET Core (this package) mailkite-aspnetcore (not yet mirrored) NuGet (not yet published)
MailKite for Laravel laravel Packagist
MailKite for Node.js mailkite-node npm
MailKite for Python mailkite-python PyPI
MailKite for Ruby mailkite-ruby RubyGems
MailKite for Java mailkite-java Maven Central
MailKite for PHP mailkite-php Packagist
MailKite for Go mailkite-go Go modules

Docs & links

MIT licensed. © MailKite.

About

MailKite.AspNetCore — native IEmailSender for ASP.NET Core Identity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages