Domain Validation
Monday, July 6, 2009
After sending a mail we need to validate for domain as well as account whether "To" or "From" mail id and domain are valid or not, it can be validate from .NET code using System.Net.Sockets.
Note: Use of sockets requires a trust level above the default "Medium".
Namespace
using System.Net;
using System.Net.Sockets;
C# Code
string email = "recipient@domain.com";
string[] host = email.Split('@');
string hostName = host[1];
Socket socket;
try
{
IPHostEntry entry = Dns.GetHostEntry(hostName);
IPEndPoint endPoint = new IPEndPoint(entry.AddressList[0], 25);
socket = new Socket(endPoint.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
socket.Connect(endPoint);
}
catch (SocketException ex)
{
// Invalid email.
}
0 comments:
Post a Comment