I'm sending email using smtp services in my c# windows application. I have to perform in a best way to reduce the email bounce rate. I have to check the provided email address is valid or not. I'm using the code.
private void btnCheckValid_Click(object sender, EventArgs e)
{
if (isRealDomain(textBox1.Text.Trim()) == true)
MessageBox.Show("Valid Email Address!");
}
private bool isRealDomain(string inputEmail)
{
bool isReal = false;
try
{
string[] host = (inputEmail.Split('@'));
string hostname = host[1];
IPHostEntry IPhst = Dns.GetHostEntry(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s = new Socket(endPt.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
s.Connect(endPt);
s.Close();
isReal = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
isReal = false;
}
return isReal;
}
By checking the real domain I can identified the Hosted IP but the email address is created on the host or not.
with regex (regular expression ) I can valid only format.
So my question is how to find only valid address of any domain in c#.