When I connect to the SMTP server for testing purposes, the connection is always slow. It takes 2 seconds to establish the connection.
This is because localhost is first resolved to ::1 and a connection is only established when it falls back to 127.0.0.1.
I'd like to change this so that we can also support IPv6.
src\SmtpServer\EndpointDefinitionBuilder.cs
Open IPv4
/// <summary>
/// Adds an endpoint with the given port.
/// </summary>
/// <param name="port">The port for the endpoint to listen on.</param>
/// <returns>The endpoint builder to continue building on.</returns>
public EndpointDefinitionBuilder Port(int port)
{
_setters.Add(definition => definition.Endpoint = new IPEndPoint(IPAddress.Any, port));
return this;
}
Open IPv6
/// <summary>
/// Adds an endpoint with the given port.
/// </summary>
/// <param name="port">The port for the endpoint to listen on.</param>
/// <returns>The endpoint builder to continue building on.</returns>
public EndpointDefinitionBuilder Port(int port)
{
_setters.Add(definition => definition.Endpoint = new IPEndPoint(IPAddress.IPv6Any, port));
return this;
}
src\SmtpServer\Net\EndpointListenerFactory.cs
With DualMode we have IPv4 and IPv6 support.
/// <inheritdoc />
public virtual IEndpointListener CreateListener(IEndpointDefinition endpointDefinition)
{
var tcpListener = new TcpListener(endpointDefinition.Endpoint);
tcpListener.Server.DualMode = true;
tcpListener.Start();
var endpointEventArgs = new EndpointEventArgs(endpointDefinition, tcpListener.LocalEndpoint);
OnEndpointStarted(endpointEventArgs);
return new EndpointListener(tcpListener, () => OnEndpointStopped(endpointEventArgs));
}
Required changes
src\SmtpServer\EndpointDefinitionBuilder.cs
_setters.Add(definition => definition.Endpoint = new IPEndPoint(IPAddress.IPv6Any, port));
src\SmtpServer\Net\EndpointListenerFactory.cs
tcpListener.Server.DualMode = true;
When I connect to the SMTP server for testing purposes, the connection is always slow. It takes 2 seconds to establish the connection.
This is because
localhostis first resolved to::1and a connection is only established when it falls back to127.0.0.1.I'd like to change this so that we can also support IPv6.
src\SmtpServer\EndpointDefinitionBuilder.csOpen IPv4
Open IPv6
src\SmtpServer\Net\EndpointListenerFactory.csWith
DualModewe have IPv4 and IPv6 support.Required changes
src\SmtpServer\EndpointDefinitionBuilder.cssrc\SmtpServer\Net\EndpointListenerFactory.cs