Some say it's impossible to verify that an email exists, but I also read it can be done by sending a message to it. So I want to verify if the email exists or not by sending it email.
Here is my code:
private void email_checker()
MailMessage mm = new MailMessage();
//The email that needs to be checked
mm.To.Add(new MailAddress(txtEmailAddress.Text, "Email Check"));
mm.From = new MailAddress("*******@gmail.com");
mm.Body = "Verified";
mm.IsBodyHtml = true;
mm.Subject = "Verification";
SmtpClient smc1 = new SmtpClient();
smc1.Host = "smtp.gmail.com";
smc1.Port = 587;
smc1.Credentials = new NetworkCredential("*****@gmail.com","********");
smc1.EnableSsl = true;
This code is functioning, but I tried to type any random email that does not exist (it really does not exist) and the code still sends a message to it. I wanted to create a popup message that prompts whenever the message has failed to sent in that way I'll know that the email really does not exist. Or is there really no other way than sending a verification link?
There is no way to see if an email exists. Remember that your code used to send an email is asking an SmtpClient to send the email. You will only get an exception if the client's server throws one. The client's server in your case is GMail. GMail doesn't fail on sending, but replies back to the sender that the email address wasn't found. Different servers behave differently. You can setup your own server to automatically retry emails or just fail silently or throw an exception, etc. Also, servers use dns so it's possible to have an intranet mail system where the email is valid to the network, but not the internet. Another thing to keep in mind is the catch all email addresses that can be setup. So the email address in question may not be valid, but caught by the catch all and then delivered to the valid address.
So, no possible way, as of now, to validate the existence of an email address.