I implemented this for myself, but I would like some mechanism that allows a caller to set a Smtp.Host = "12.1.2.3", which would connect to the TcpClient differently, and not attempt to do name resolution. I want this functionality to reduce my failure points. The email sender can then work with or without our DNS server. I have attached my changed version of Smtp.cs, based on the 2005-02-16 release.
I can think of 2 implementations: One would use a flag for "This Host is an IP Address", and the other one would compare hosts to a Regular Expression.
A partial implementation follows:
public class Smtp
{
internal bool isHostIP = false;
...
public bool IsHostIP
{
get{ return this.isHostIP; }
set{ this.isHostIP = value; }
};
...
private NetworkStream GetConnection()
{
... validate input ...
tcpc = new TcpClient();
if (isHostIP)
{
IPAddress addr = IPAddress.Parse(host);
tcpc.Connect(addr, port);
}
else
{
tcpc.Connect(host, port);
}
...
}