SmtpResponse SendEhlo (bool ehlo, CancellationToken cancellationToken)
{
string command = ehlo ? "EHLO " : "HELO ";
#if !NETFX_CORE
string domain = null;
IPAddress ip = null;
if (!string.IsNullOrEmpty (LocalDomain)) {
if (!IPAddress.TryParse (LocalDomain, out ip))
domain = LocalDomain;
} else if (Stream.Socket != null) {
var ipEndPoint = Stream.Socket.LocalEndPoint as IPEndPoint;
if (ipEndPoint == null)
domain = ((DnsEndPoint) Stream.Socket.LocalEndPoint).Host;
else
ip = ipEndPoint.Address;
} else {
domain = "[127.0.0.1]";
}
if (ip != null) {
if (ip.AddressFamily == AddressFamily.InterNetworkV6)
domain = "[IPv6:" + ip + "]";
else
domain = "[" + ip + "]";
}
command += domain;
#else
if (!string.IsNullOrEmpty (LocalDomain))
command += LocalDomain;
else if (!string.IsNullOrEmpty (Stream.Socket.Information.LocalAddress.CanonicalName))
command += Stream.Socket.Information.LocalAddress.CanonicalName;
else
command += "localhost.localdomain";
#endif
return SendCommand (command, cancellationToken);
}