Send email from .NET over SMTP
System.Net.Mail.SmtpClient is obsolete. Use MailKit, STARTTLS on 587, username `unitpost`, API key as password.
What are the SMTP settings?
| Host | smtp.unitpost.com |
|---|---|
| Username | unitpost(always this literal value) |
| Password | Your Unitpost API key(must carry emails:send) |
| Port (STARTTLS) | 587(or 2587 if blocked) |
| Port (implicit TLS) | 465(or 2465 if blocked) |
| From address | Any address on a verified domain |
How do I set it up?
Add MailKit
Shelldotnet add package MailKitSend
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);Verify delivery
Confirm in Activity.