.NET
MailKit against a sandbox — connect, authenticate, send.
Before you start
- .NET 6 or later
- MailKit
1Add MailKit
dotnet add package MailKit2Send a test message
using MailKit.Net.Smtp; using MailKit.Security; using MimeKit; var message = new MimeMessage(); message.From.Add(MailboxAddress.Parse("staging@example.com")); message.To.Add(MailboxAddress.Parse("anyone@example.com")); message.Subject = "Sandbox check"; message.Body = new TextPart("html") { Text = "<h1>Hello from .NET</h1>" }; using var client = new SmtpClient(); await client.ConnectAsync("smtp.mailclutch.com", 587, SecureSocketOptions.StartTls); await client.AuthenticateAsync("mc_0000000000000000", "pw_0000000000000000"); await client.SendAsync(message); await client.DisconnectAsync(true);
3Or configure ASP.NET
If your app reads its mail settings from configuration, the same values go in appsettings.Development.json:
{ "Smtp": { "Host": "smtp.mailclutch.com", "Port": 587, "Username": "mc_0000000000000000", "Password": "pw_0000000000000000" } }
Watch it land
Open the sandbox and the message is there — rendered HTML, plain text, raw source, attachments, and the SPF, DKIM and DMARC verdicts. It updates live, so you can leave it open next to your terminal.
Nothing is ever delivered onward, whatever address you send to; claim the inbox with an account and it stays.
Awaiting your email
Send from any address; it stops here rather than going onward. The inbox keeps what it catches for 24 hours.
What usually goes wrong
System.Net.Mail.SmtpClient
The built-in client still works —
new SmtpClient("smtp.mailclutch.com", 587) { Credentials = new NetworkCredential(user, pass), EnableSsl = true }— but Microsoft marks it obsolete for new code, which is why MailKit is shown first.SecureSocketOptions
StartTlsfor 587,SslOnConnectfor 465.Autoalso works;Nonewill fail authentication.
Other stacks
The same four values in another dialect. Every guide below is filled in with the sandbox pair at the top of this page.
Frameworks and languages
- LaravelFive .env variables, no package
- SymfonyOne MAILER_DSN
- DjangoFive settings, nothing installed
- RailsAction Mailer smtp_settings
- Node.jsA Nodemailer transport
- Next.jsRoute Handler or Server Action
- Gonet/smtp, standard library
- SpringFive Spring Boot properties
- JavaJakarta Mail, no framework
- PHPPHPMailer, no framework
- Pythonsmtplib, standard library
- Rustlettre over a STARTTLS relay