Send email from .NET over SMTP

System.Net.Mail.SmtpClient is obsolete. Use MailKit, STARTTLS on 587, username `unitpost`, API key as password.

Need an API key?

SMTP password is a Unitpost API key with emails:send. Username is always unitpost.

  • 5,000 emails/month
  • 3 API keys
  • 5 sending domains
Get free SMTP key
  1. Add MailKit

    Shell
    dotnet add package MailKit
  2. Send

    C#
    using MailKit.Net.Smtp;
    using MailKit.Security;
    using MimeKit;
    
    var message = new MimeMessage();
    message.From.Add(MailboxAddress.Parse("you@yourdomain.com"));
    message.To.Add(MailboxAddress.Parse("customer@example.com"));
    message.Subject = "Hello from .NET";
    message.Body = new TextPart("html") { Text = "<p>Sent via SMTP.</p>" };
    
    using var client = new SmtpClient();
    await client.ConnectAsync("smtp.unitpost.com", 587, SecureSocketOptions.StartTls);
    await client.AuthenticateAsync("unitpost", Environment.GetEnvironmentVariable("UNITPOST_API_KEY"));
    await client.SendAsync(message);
    await client.DisconnectAsync(true);
  3. Verify delivery

    Confirm in Activity.

Search docs and guides

Search the docs and product guides.