Menu

#21 Allow SMTP connection using IP Address

open
nobody
None
5
2005-04-16
2005-04-16
Anonymous
No

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);
}
...
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.