-1

I am trying to validate an email whether it is real or fake. I am using some code but it always returns Ok.

This is my code:

public string validateEmail(string userEmail)
{
        try
        {
            string key = "xxxx";
            string email = "xxxx";
            var crmUrl = "https://app.emaillistvalidation.com/api/verifEmail?secret=" + key + "&email=" + email;
            string url = crmUrl;

            var client = new RestClient(url);
            client.RemoteCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });

            var request = new RestRequest();
            request.AddHeader("authorization", "Basic xxxxxxxxxxxxxxxxxx");

            IRestResponse response = client.Execute(request);

            var content = response.Content;
            return content;
        }
        catch (Exception ex)
        {
        }

        return default;
}

What is wrong here? And what can I do instead?

6
  • 1
    You say "it" always returns Ok. What is "it"? Is it your method? The call to app.emaillistvalidation.com? Why do you have an empty catch block? Commented Aug 31, 2022 at 16:51
  • @mason yes the method is returning ok always. Commented Aug 31, 2022 at 17:59
  • Why do you have an empty catch block? Have you verified if an exception is being thrown or not? How have you verified? Commented Aug 31, 2022 at 18:13
  • There is no issues with the catch block. The problem is with the api. It is returning Ok for all valid and Invalid email.. Commented Aug 31, 2022 at 18:27
  • You just said the method is always returning OK. Now you're saying the API. Which is it? Commented Aug 31, 2022 at 20:05

1 Answer 1

1

I am trying to validate an email whether it is real or fake. I am using some code but it always returns Ok.

I have gone through the code and the API you have shared. I also register and open a demo api on https://app.emaillistvalidation.com/api and it's behaving as expected for both valid and invalid email. Here are my steps:

Register on app.emaillistvalidation.com

enter image description here

My Controller Code

        [Route("ValidateEmail")]
        [HttpGet]
        public async Task<IActionResult> ValidateEmail(string emailId)
        {
            var handler = new HttpClientHandler();
            var data = "";

            handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
            var client = new HttpClient(handler);
            client.DefaultRequestHeaders.Accept.Clear();

            var responseFromApi = await client.GetAsync("https://app.emaillistvalidation.com/api/verifEmail?secret=" + apiSecret + "&email=" + emailId + "");
            if (responseFromApi.IsSuccessStatusCode)
            {
                data = await responseFromApi.Content.ReadAsStringAsync();
               
            }

            return Ok(data);
        }

Output For Valid & Invalid Email

enter image description here

Postman Direct Test

I have also tested on Postman for valid email I got ok response and for invalid and wrong email I got unknown and disable response:

Valid Email:

enter image description here

Wrong Email:

enter image description here

Wrong Domain:

enter image description here

Note: Please double-check the way you are trying. You could have a look on my code and the way I have tested. It's working as expected which has been shared in the screenshots

Sign up to request clarification or add additional context in comments.

2 Comments

My code was right. I was testing in wrong way. Thank you. Seeing your code I found my mistake...
Glad to assist you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.