Usage of email validation using C#

Download Api from GitHub

Api One By One


    public static void verifyByOne()
    {
            string key = "You Key Here";
            string email = "example@company.com";
            string sURL = "https://apps.emaillistverify.com/api/verifyEmail?secret=" + key + "&email=" + email;
            WebRequest wrGETURL;
            wrGETURL = WebRequest.Create(sURL);

            WebProxy myProxy = new WebProxy("myproxy", 80);
            myProxy.BypassProxyOnLocal = true;

            wrGETURL.Proxy = WebProxy.GetDefaultProxy();

            Stream objStream;
            objStream = wrGETURL.GetResponse().GetResponseStream();

            StreamReader objReader = new StreamReader(objStream);

            string sLine = "";
            int i = 0;

            while (sLine != null)
            {
                i++;
                sLine = objReader.ReadLine();
                if (sLine != null)
                    Console.WriteLine("{0}:{1}", i, sLine);
            }
            Console.ReadLine();
    }
		   

Main Status Responses

Status="ok"- A ok response is an address that has passed all tests. The address provided passed all tests.

Status="fail"- A failed response is an address that has failed 1 or more tests.

  • The address provided does not exist.
  • The mailbox is full.
  • The address provided is a disposable email address.
  • The address provided is not in a valid format.
  • The address provided is a role account.
  • The address provided does not have a valid dns.
  • The address provided does not have a mx server.
  • The address provided was found in your internal blacklist containing previously failed addresses.
  • The domain provided was found in your domain blacklist.

Status="unknown"- A unknown response is an address that can not be accurately tested. Is a Catchall mx server config. Greylisting is active on this server, please try again in a few minutes. Greylisting is suspected to be active on this server, please try again in a few minutes. The address provided can not be verified at this time.

Status="incorrect"- No email provided in request. Email syntax error (example: myaddress[at]gmail.com, must be myaddress@gmail.com)

Status=" key_not_valid"- No api key provided in request or invalid.

Status=" missing parameters"- There are no validations remaining to complete this attempt.


Api - Bulk emails verification


    private static void uploadFile()
        {
            string key = "You Key Here";

            string file_contents = "c:\\php\\emails.txt";
            string url = "https://apps.emaillistverify.com/api/verifyApiFile?secret=" + key + "&filename=my_emails.txt";

            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
            //I use a method to ignore bad certs caused by misc errors
            IgnoreBadCertificates();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.ContentType = "multipart/form-data; boundary=" + boundary;
            request.Method = "POST";
            //request.ServicePoint.Expect100Continue = false;
            request.KeepAlive = false;

            string header = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file_contents\"; filename=\"" + file_contents + "\"\r\nContent-Type: application/octet-stream\r\n\r\n";

            string trailer = "\r\n--" + boundary + "--\r\n";

            //name="file_contents"; filename="c:\php\emails.txt"

            byte[] bytesHeader = Encoding.ASCII.GetBytes(header);
            byte[] bytesFileContent = File.ReadAllBytes(file_contents);
            byte[] bytesTrailer = Encoding.ASCII.GetBytes(trailer);

            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytesHeader, 0, bytesHeader.Length);
            requestStream.Write(bytesFileContent, 0, bytesFileContent.Length);
            requestStream.Write(bytesTrailer, 0, bytesTrailer.Length);
            requestStream.Close();

            try
            {
                using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
                {
                    string id = reader.ReadToEnd();
                    CheckState(id);

                };
            }
            catch (Exception ex)
            {
                // something strange...
            }
        }
		   

Get file info with API:


   private static void CheckState(string id)
        {
            string key = "You Key Here";
            string sURL = "https://apps.emaillistverify.com/api/getApiFileInfo?secret=" + key + "&id=" + id;
            WebRequest wrGETURL;
            wrGETURL = WebRequest.Create(sURL);

            WebProxy myProxy = new WebProxy("myproxy", 80);
            myProxy.BypassProxyOnLocal = true;

            wrGETURL.Proxy = WebProxy.GetDefaultProxy();

            Stream objStream;
            objStream = wrGETURL.GetResponse().GetResponseStream();

            StreamReader objReader = new StreamReader(objStream);

            string sLine = "";
            int i = 0;

            while (sLine != null)
            {
                i++;
                sLine = objReader.ReadLine();
                if (sLine != null)
                    Console.WriteLine("{0}:{1}", i, sLine);
            }
        }