jstedfast/MailKit · error · NotSupportedException
The default system proxy does not support
Error message
The default system proxy does not support {proxyUri.Scheme}. What it means
ProxyClient.GetProxyClient resolves the system default proxy (from system proxy settings / IWebProxy) and only knows how to build clients for socks4, socks4a and socks5 proxy URIs. When the system proxy URI uses any other scheme (http, https), it throws NotSupportedException because MailKit's default-proxy helper cannot create a client for it.
Solutions
- Change the system proxy setting to a socks5:// URI, or
- Do not rely on the default system proxy: construct the appropriate client explicitly (e.g. Socks5Client) or use an HTTP-proxy-capable alternative (HttpProxyClient if available in your MailKit version).
- Inspect the resolved proxyUri.Scheme before calling to know which scheme will be used.
Example fix
// before
var client = ProxyClient.GetProxyClient(); // system proxy is http://proxy:8080
// after
var client = new Socks5Client("proxy.corp.com", 1080, credential); // explicit SOCKS5 proxy Defensive patterns
Strategy: validation
Validate before calling
var proxy = ProxyClient.GetDefaultProxy(); // or inspect system proxy
if (proxy != null && !proxy.Uri.Scheme.StartsWith("socks", StringComparison.OrdinalIgnoreCase))
throw new NotSupportedException($"System proxy scheme '{proxy.Uri.Scheme}' is not supported; configure a socks5:// proxy or create the client manually"); Type guard
bool IsSupportedProxyUri(Uri u) => u != null && (u.Scheme == "socks4" || u.Scheme == "socks4a" || u.Scheme == "socks5");
Try / catch
ProxyClient client;
try {
client = ProxyClient.GetProxyClient();
} catch (NotSupportedException ex) {
// system proxy is http/https; fall back to explicit SOCKS5 client
client = new Socks5Client("proxy.corp.com", 1080);
} Prevention
- Set system/environment proxy URIs with a socks5:// scheme when using MailKit's default proxy helper
- Prefer explicitly constructing the proxy client over system detection
- Log the resolved proxy URI scheme during startup to catch this early
When it happens
Trigger: Using ProxyClient.GetProxyClient with system proxy detection enabled while the OS/environment is configured with an HTTP or HTTPS proxy URL (e.g. http://proxy:8080 in HTTP_PROXY / Windows proxy settings).
Common situations: Corporate environments that publish HTTP proxies via environment variables or system settings; developers assuming MailKit can tunnel through an HTTP CONNECT proxy automatically.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Failed to connect to
- Failed to connect to
- Failed to negotiate authentication method with the proxy…
- Specified argument was out of the range of valid values…
- No credentials could be found for the IMAP server.
AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15).
Data as JSON: /api/errors/c635074a76abaded.
Report an issue: GitHub.
Appendix: source
Thrown at MailKit/Net/Proxy/WebProxyClient.cs:129
return new Socks4Client (proxyUri.Host, proxyUri.Port);
}
if (proxyUri.Scheme.Equals ("socks4a", StringComparison.OrdinalIgnoreCase)) {
if (credential != null)
return new Socks4aClient (proxyUri.Host, proxyUri.Port, credential);
return new Socks4aClient (proxyUri.Host, proxyUri.Port);
}
if (proxyUri.Scheme.Equals ("socks5", StringComparison.OrdinalIgnoreCase)) {
if (credential != null)
return new Socks5Client (proxyUri.Host, proxyUri.Port, credential);
return new Socks5Client (proxyUri.Host, proxyUri.Port);
}
throw new NotSupportedException ($"The default system proxy does not support {proxyUri.Scheme}.");
}
/// <summary>
/// Connect to the target host.
/// </summary>
/// <remarks>
/// Connects to the target host and port through the proxy server.
/// </remarks>
/// <returns>The connected network stream.</returns>
/// <param name="host">The host name of the target server.</param>
/// <param name="port">The target server port.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="host"/> is <see langword="null" />.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="port"/> is not between <c>0</c> and <c>65535</c>.
/// </exception>View on GitHub (pinned to 9d3859a785)