If you searched for `csharp send smtp email`, a production-safe answer is:

1. use a maintained SMTP client library
2. configure auth and TLS explicitly
3. externalize SMTP settings per environment
4. verify inbox outcomes with integration tests

![csharp smtp](/assets/csharp-smtp.jpg)

## Quick setup with MailKit

Install packages:

```bash
dotnet add package MailKit
dotnet add package MimeKit
```

Minimal SMTP send example:

```csharp
using MailKit.Net.Smtp;
using MailKit.Security;
using MimeKit;

var message = new MimeMessage();
message.From.Add(MailboxAddress.Parse("no-reply@example.com"));
message.To.Add(MailboxAddress.Parse("user@example.com"));
message.Subject = "Welcome";
message.Body = new TextPart("plain") { Text = "Your account is ready." };

using var client = new SmtpClient();
await client.ConnectAsync("smtp.example.com", 587, SecureSocketOptions.StartTls);
await client.AuthenticateAsync("smtp-user", "smtp-password");
await client.SendAsync(message);
await client.DisconnectAsync(true);
```

## SMTP settings .NET teams should standardize

For stable delivery, define and validate:

- SMTP host and port
- auth method and credential rotation
- TLS mode and certificate behavior
- sender-domain alignment for SPF, DKIM, and DMARC
- timeout and retry policies for transient failures

Related references:

- [SMTP authentication](/blog/smtp-authentication/)
- [STARTTLS vs SSL/TLS](/blog/starttls-ssl-tls/)
- [SMTP ports guide](/guides/what-are-smtp-ports/)

## Environment-driven C# SMTP configuration

```csharp
var smtpHost = Environment.GetEnvironmentVariable("SMTP_HOST")!;
var smtpPort = int.Parse(Environment.GetEnvironmentVariable("SMTP_PORT")!);
var smtpUser = Environment.GetEnvironmentVariable("SMTP_USERNAME")!;
var smtpPass = Environment.GetEnvironmentVariable("SMTP_PASSWORD")!;
var fromAddress = Environment.GetEnvironmentVariable("SMTP_FROM_ADDRESS")!;
```

Using env-driven config keeps staging/production parity and secret rotation manageable.

## Common C# SMTP failures and fixes

### Authentication failures (`535` or login exceptions)

Likely causes:

- stale credentials
- incorrect auth mechanism
- sender-domain policy misalignment

Fix by validating credentials and sender-domain auth posture together.

### TLS/connection failures

Likely causes:

- wrong port + TLS combination
- certificate trust issues
- outbound egress restrictions

Fix by validating transport mode, trust policy, and network configuration.

### SMTP send succeeds but email not visible in inbox

SMTP acceptance does not guarantee inbox placement.

Run deliverability diagnostics:

- [Email deliverability test](/testing/email-deliverability-test/)
- [Email spam checker](/tools/email-spam-checker/)

## Test C# SMTP workflows before release

Cover deterministic inbox assertions for:

- signup and account verification
- password reset and magic links
- invoices and transactional notifications
- operational alerts

Recommended workflow pages:

- [Email Sandbox](/product/email-sandbox/)
- [Email integration testing](/product/email-integration-testing/)
- [Email webhooks](/guides/email-webhooks/)

## C# SMTP production checklist

1. Keep SMTP auth/TLS/host/port in environment-managed config.
2. Validate SPF, DKIM, and DMARC alignment before release.
3. Add inbox-based assertions for critical user journeys.
4. Add retry/timeout policy for transient SMTP failures.
5. Re-test after DNS, template, or provider changes.

## FAQ

### Should I use `System.Net.Mail.SmtpClient` or MailKit?

For new development, many teams prefer MailKit because it is actively maintained and better suited for modern SMTP workflows.

### Can I still use `System.Net.Mail` in existing apps?

Yes, but apply the same auth/TLS/testing controls and plan modernization for long-term maintainability.

### How do I validate C# SMTP changes in CI?

Use isolated inboxes with deterministic receive assertions, not only SMTP send success responses.

## Next steps

- [SMTP and IMAP guide](/guides/smtp-imap/)
- [Deliverability testing workflow](/testing/email-deliverability-test/)
- [Email Sandbox setup](/product/email-sandbox/)
