Ive seen some php examples of how you can ping an inbox(without sending any mail to it) to check whether it exists. I was wondering if anyone knows if this is possible with .net? If it is Im going to write an app to do a bulk check on list of emails i have captured through my site.
-
11Not only is it not possible in .NET, it is not remotely possible at all. – Kirk Woll Oct 07 '10 at 16:01
-
2possible duplicate of [How to check if an email address exists without sending an email?](http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email) – Daniel DiPaolo Oct 07 '10 at 16:04
-
3@Daniel, I think that is what phil meant by "I've seen some php examples", this question is about .NET. Of course, "there's no reliable way" is the correct answer regardless of language. – Ben Voigt Oct 07 '10 at 16:07
-
Some what related to this topic - http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html – Ahmad Oct 07 '10 at 19:22
7 Answers
SMTP defines the VRFY
command for this, but since abuse by spammers totally overwhelmed the number of legitimate uses, virtually every e-mail server in the world is configured to lie.

- 19,168
- 12
- 41
- 79

- 277,958
- 43
- 419
- 720
-
5+1 for explaining exactly why there is no reliable way to do what the OP wants. On a personal note, anything that makes bulk e-mail harder is unquestionably a good thing. – Joel Mueller Oct 07 '10 at 16:28
-
@Joel: Well, there *is* legitimate bulk mail (mailing lists etc.). But it's true that most bulk mail is illegitimate, even though that is deplorable. – sleske Oct 09 '10 at 20:42
-
But I want to use this to prevent spammers from spamming contact forms on websites... (irony) – Pieterjan Oct 20 '22 at 10:16
What you mean about if you writing "check email"? Without sending some unique link for email owner you can't check this, you can only check syntax of email, and connection to smtp.
public static bool isEmail(string inputEmail)
{
inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
smtp check
string[] host = (address.Split('@'));
string hostname = host[1];
IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s= new Socket(endPt.AddressFamily,
SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt);

- 16,203
- 6
- 66
- 100
No, it is impossible in principle to check if an email exists - independent of language. There is simply no protocol to do it.
There are some partial solutions, but none of them are reliable.
See How to check if an email address exists without sending an email? for details.
1. Get the MX record for the email provider by using following command:
nslookup -type=mx gmail.com
Make call to tcp client to check if email is valid:
private static void Main(string[] args) { var gMail = IsEmailAccountValid("gmail-smtp-in.l.google.com", "aa.aa@gmail.com"); Console.WriteLine($"Gmail account is valid - {gMail.ToString()}"); var live = IsEmailAccountValid("live-com.olc.protection.outlook.com", "aa.aa@live.com"); Console.WriteLine($"Live account is valid - {live.ToString()}"); } private static byte[] BytesFromString(string str) { return Encoding.ASCII.GetBytes(str); } private static int GetResponseCode(string ResponseString) { return int.Parse(ResponseString.Substring(0, 3)); } private static bool IsEmailAccountValid(string tcpClient, string emailAddress) { TcpClient tClient = new TcpClient(tcpClient, 25); string CRLF = "\r\n"; byte[] dataBuffer; string ResponseString; NetworkStream netStream = tClient.GetStream(); StreamReader reader = new StreamReader(netStream); ResponseString = reader.ReadLine(); /* Perform HELO to SMTP Server and get Response */ dataBuffer = BytesFromString("HELO Hi" + CRLF); netStream.Write(dataBuffer, 0, dataBuffer.Length); ResponseString = reader.ReadLine(); dataBuffer = BytesFromString("MAIL FROM:<YourGmailIDHere@gmail.com>" + CRLF); netStream.Write(dataBuffer, 0, dataBuffer.Length); ResponseString = reader.ReadLine(); /* Read Response of the RCPT TO Message to know from google if it exist or not */ dataBuffer = BytesFromString($"RCPT TO:<{emailAddress}>" + CRLF); netStream.Write(dataBuffer, 0, dataBuffer.Length); ResponseString = reader.ReadLine(); var responseCode = GetResponseCode(ResponseString); if (responseCode == 550) { return false; } /* QUITE CONNECTION */ dataBuffer = BytesFromString("QUITE" + CRLF); netStream.Write(dataBuffer, 0, dataBuffer.Length); tClient.Close(); return true; }
The MX record can be obtained using code:
var lookup = new LookupClient();
var result = lookup.QueryAsync("gmail.com", QueryType.ANY).Result;
var domainName = result.Additionals[result.Additionals.Count - 1].DomainName.Value;
Using above code find the MX lookup and use that MX lookup to check if email is valid or not.

- 1,726
- 1
- 20
- 33

- 215
- 4
- 7
-
-
It's a DnsClient Nugut Package Class Help to Get DNS Records – Muhammad Usama Alam Oct 20 '21 at 00:37
http://www.codicode.com/art/free_asp_net_email_validator_verifier.aspx. Use the dll reference to your code. It is free both for personal use and redistribution. It checks for the domain name existence without actually sending an email.

- 2,588
- 5
- 28
- 39
This is not foolproof. The best you can do is check syntax and see if the domain name resolves.
Email syntax RegEx:
(?<username>#?[_a-zA-Z0-9-+]+(\.[_a-zA-Z0-9-+]+)*)@(?<domain>[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|arpa|asia|coop|info|jobs|mobi|museum|name|travel)))

- 15,361
- 6
- 36
- 57
-
1Well I did not down wote but it might be because the question specifically asks for a solution to ping the server, not check syntax. Maybe the question was changed after your answer. – David Mårtensson Feb 28 '11 at 10:48
protected bool checkDNS(string host, string recType = "MX")
{
bool result = false;
try
{
using (Process proc = new Process())
{
proc.StartInfo.FileName = "nslookup";
proc.StartInfo.Arguments = string.Format("-type={0} {1}", recType, host);
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.ErrorDialog = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
{
if ((e.Data != null) && (!result))
result = e.Data.StartsWith(host);
};
proc.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
{
if (e.Data != null)
{
//read error output here, not sure what for?
}
};
proc.Start();
proc.BeginErrorReadLine();
proc.BeginOutputReadLine();
proc.WaitForExit(30000); //timeout after 30 seconds.
}
}
catch
{
result = false;
}
return result;
}

- 9
- 1
-
This has been tested and is working. I basically converted the php example. – Gary Mason Jan 26 '15 at 21:52