0

so I finished developping a CRM web app but still have a problem verifying if a given email exists or not, so I googled if some free apis exists and found one but i couldn't integrate it's code in my app as it's writin in .net but i am using .net core, So here's the code:

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Web.Script.Serialization;

namespace PermissionManagement.MVC
{
    public class APIResult
    {
        private class APIResults
        {
            public int status { get; set; }
            public string info { get; set; }
            public string details { get; set; }
        }

        public void Checkemail(string mail)
        {
            const String APIURL = "https://api.email-validator.net/api/verify";
            HttpClient client = new HttpClient();
            String Email = mail;
            String APIKey = "hidden";

            var postData = new List<KeyValuePair<string, string>>();
            postData.Add(new KeyValuePair<string, string>("EmailAddress", Email));
            postData.Add(new KeyValuePair<string, string>("APIKey", APIKey));

            HttpContent content = new FormUrlEncodedContent(postData);

            HttpResponseMessage result = client.PostAsync(APIURL, content).Result;
            string resultContent = result.Content.ReadAsStringAsync().Result;
            

            // HERE IS THE ERROR
            APIResults res = new JavaScriptSerializer().
            Deserialize<APIResult>(resultContent);

            switch (res.status)
            {
                // valid addresses have a {200, 207, 215} result code
                // result codes 114 and 118 need a retry
                case 200:
                case 207:
                case 215:
                    // address is valid
                    // 215 - can be retried to update catch-all status
                    break;
                case 114:
                    // greylisting, wait 5min and retry
                    break;
                case 118:
                    // api rate limit, wait 5min and retry
                    break;
                default:
                    // address is invalid
                    // res.info
                    // res.details
                    break;
            }
        }
    }

}

I marked the error with a comment as you can see and also it keeps showing an error in the using statement (using System.Web.Script.Serialization;)

Can anyone help me convert it so I can use it

4
  • Does this answer your question? JavaScriptSerializer is not allowed in .net core project? Commented Jun 20, 2021 at 15:26
  • Actually i've tried some itellisense suggestion and it worked, it seemed that i had to install a nuget package called Nancy.json and now it works fine Commented Jun 20, 2021 at 15:34
  • Why do you need an API to check if email exists when you can do that with remote validation? Commented Jun 20, 2021 at 16:19
  • I don't know this remote validation because am new but I would know how this method works cause this api isn't free Commented Jun 22, 2021 at 0:28

0

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.