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

  • Does this answer your question? [JavaScriptSerializer is not allowed in .net core project?](https://stackoverflow.com/questions/54110411/javascriptserializer-is-not-allowed-in-net-core-project) – Epic Chen Jun 20 '21 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 – amir chouika Jun 20 '21 at 15:34
  • Why do you need an API to check if email exists when you can do that with remote validation? – Harkirat singh Jun 20 '21 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 – amir chouika Jun 22 '21 at 00:28

0 Answers0