dotnet / dotnet/runtime

[API Proposal]: SmtpClient.SslOptions

Open
#120,965 1 comment 2 reactions 0 assignees View on GitHub
api-ready-for-review area-System.Net
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Background and motivation

`SmtpClient` can be configured to use TLS via `SmtpClient.EnableSsl` property, but at this time, there is no way to configure the actual TLS connection parameters (client certs, remote certificate validation, etc). This is one of the last areas that is still affected by `ServicePointManager` (for SslProtocols and cert validation).

### API Proposal

```diff
namespace System.Net.Mail;

public partial class SmtpClient
{
// lazily initialized on get;, has no effect if EnableSsl == false
+ public SslClientAuthenticationOptions SslOptions { get; set; }

// existing member
+ [Obsolete("Use SslOptions.ClientCertificates instead")]
public X509CertificatesCollection ClientCertificates { get; } // => SslOptions.ClientCertificates
}
```

### API Usage

```csharp
SmtpClient client = new(...) {
SslOptions = {
ClientCertificates = new () { myClientCertificate },
RemoteCertificateValidationCallback = delegate { return true; }, // imagine complicated validation logic here,

TargetHost = "smtp.somehost.com" // if not set, defaults to SmtpClient.Host,

// there is no smtp in IANA registry, so ALPN is not used with SMTP, but we would probably respect whatever user
// decided they want to send
// ApplicationProtocols = [ new SslApplicationProtocol("whatever-i-want") ]

// other members omited for brevity
}
}
```

### Alternative Designs

_No response_

### Risks

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.