System.Net.Mail and use MailKit instead for reliable email delivery.
Prerequisites
Before sending, verify your domain and create an SMTP credential. Use a sandbox credential for these examples so no email is delivered. Keep the username and password in your server’s secret store. Before you begin, ensure you have:Development Environment
Development Environment
- .NET SDK installed (.NET 6.0 or higher recommended)
- Visual Studio or Visual Studio Code for development
- NuGet package manager access
- Basic knowledge of C# programming
Project Dependencies
Project Dependencies
- MailKit NuGet package (recommended)
- MimeKit (included with MailKit)
- Avoid using
System.Net.Mailfor PLAIN AUTH over STARTTLS
Why MailKit Over System.Net.Mail?
AhaSend works with any SMTP-compatible library, but for C#/.NET applications, we strongly recommend MailKit over the built-inSystem.Net.Mail:
✅ MailKit (Recommended)
Pros: Modern, reliable STARTTLS
Auth: AUTH PLAIN/LOGIN support
Compatibility: Works with StartTLS
Features: Rich MIME support, attachments, HTML
Auth: AUTH PLAIN/LOGIN support
Compatibility: Works with StartTLS
Features: Rich MIME support, attachments, HTML
❌ System.Net.Mail (Avoid)
Issues: Unreliable STARTTLS authentication
Auth: Silent AUTH failures with AhaSend
Status: Legacy, minimal updates
Problems: May not send AUTH commands at all
Auth: Silent AUTH failures with AhaSend
Status: Legacy, minimal updates
Problems: May not send AUTH commands at all
Connection Settings
All message data is stored in the EU. See SMTP limits.
Why System.Net.Mail Fails
The built-inSystem.Net.Mail.SmtpClient in .NET has fundamental issues with STARTTLS authentication that make it incompatible with AhaSend.
The Problem
Even with correct credentials andEnableSsl = true, the SMTP client often never issues an AUTH command after the STARTTLS handshake. This causes silent authentication failures where the connection appears to succeed but emails are rejected.
What Doesn’t Work
Here’s the problematic code that fails with AhaSend:System.Net.Mail (Don't Use This)
Debugging the Issue
You can confirm this authentication failure by capturing SMTP traffic with tools liketcpdump or Wireshark:
- Connection succeeds - Client connects to AhaSend SMTP server
- STARTTLS works - TLS encryption is established successfully
- AUTH command missing - Client never sends authentication credentials
- Silent failure - No clear error message, just rejection
Know a Workaround? If you’ve found a way to make
System.Net.Mail work reliably with AhaSend’s AUTH PLAIN over STARTTLS, please contact our support team. We’d be happy to update this guide with your solution!Use MailKit (Recommended)
MailKit is a modern, actively maintained .NET library that correctly handles SMTP authentication with AhaSend. It properly negotiates authentication mechanisms likePLAIN and LOGIN over STARTTLS.
Installation
Install MailKit via NuGet Package Manager:MimeKit Included: MailKit automatically includes MimeKit for MIME message construction. No additional packages needed!
Basic MailKit Examples
Advanced MailKit Examples
Testing with Sandbox Mode
Use sandbox mode to safely test your C# email integration:Sandbox Benefits: Emails sent in sandbox mode are free, trigger webhooks normally, and never actually deliver to recipients - perfect for development and testing.
Resources
MailKit Documentation
Official MailKit and MimeKit documentation
Microsoft .NET Docs
Comprehensive .NET development guide
MailKit GitHub
Source code, examples, and issue tracking
AhaSend Support
Get help from our engineering team
Related Guides
- Before sending: verify your domain and create an SMTP credential.
- Connection and message rules: SMTP hosts, ports and limits, special headers, sandbox mode, retention and plan features.
- Other ways to send: REST API, AhaSend CLI, Node.js SDK and Go SDK.
- Delivery events: webhook setup and local webhook testing.

