Verifier email c# online

Here is an example of how to verify an email address in C# using an online email verification service:

Using EmailVerify.net

EmailVerify.net is a popular online email verification service that provides a simple API to verify email addresses. Here's an example of how to use it in C#:

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace EmailVerifier
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string apiKey = "YOUR_API_KEY"; // Replace with your API key
            string email = "[email protected]"; // Email address to verify

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://api.emailverify.net/v1/");

                var request = new HttpRequestMessage(HttpMethod.Post, "verify")
                {
                    Content = new StringContent($"{{\"email\":\"{email}\"}}", Encoding.UTF8, "application/json")
                };

                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    var responseBody = await response.Content.ReadAsStringAsync();
                    var verificationResult = JsonConvert.DeserializeObject<VerificationResult>(responseBody);

                    if (verificationResult.IsValid)
                    {
                        Console.WriteLine($"Email {email} is valid");
                    }
                    else
                    {
                        Console.WriteLine($"Email {email} is not valid");
                    }
                }
                else
                {
                    Console.WriteLine($"Error verifying email: {response.StatusCode}");
                }
            }
        }
    }

    public class VerificationResult
    {
        public bool IsValid { get; set; }
        public string ErrorMessage { get; set; }
    }
}

Using Clearbit

Clearbit is another popular online email verification service that provides a simple API to verify email addresses. Here's an example of how to use it in C#:

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace EmailVerifier
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string apiKey = "YOUR_API_KEY"; // Replace with your API key
            string email = "[email protected]"; // Email address to verify

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://person.clearbit.com/v2/");

                var request = new HttpRequestMessage(HttpMethod.Get, $"verify-email/v2/{email}")
                {
                    Headers = { { "X-Clearbit-Token", apiKey } }
                };

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    var responseBody = await response.Content.ReadAsStringAsync();
                    var verificationResult = JsonConvert.DeserializeObject<VerificationResult>(responseBody);

                    if (verificationResult.result.valid)
                    {
                        Console.WriteLine($"Email {email} is valid");
                    }
                    else
                    {
                        Console.WriteLine($"Email {email} is not valid");
                    }
                }
                else
                {
                    Console.WriteLine($"Error verifying email: {response.StatusCode}");
                }
            }
        }
    }

    public class VerificationResult
    {
        public bool result { get; set; }
        public string message { get; set; }
    }
}

Using EmailVerification.io

EmailVerification.io is another online email verification service that provides a simple API to verify email addresses. Here's an example of how to use it in C#:

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace EmailVerifier
{
    class Program
    {
        static async Task Main(string[] args)
        {
            string apiKey = "YOUR_API_KEY"; // Replace with your API key
            string email = "[email protected]"; // Email address to verify

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://api.emailverification.io/v1/");

                var request = new HttpRequestMessage(HttpMethod.Post, "verify")
                {
                    Content = new StringContent($"{{\"email\":\"{email}\"}}", Encoding.UTF8, "application/json")
                };

                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);

                var response = await client.SendAsync(request);

                if (response.IsSuccessStatusCode)
                {
                    var responseBody = await response.Content.ReadAsStringAsync();
                    var verificationResult = JsonConvert.DeserializeObject<VerificationResult>(responseBody);

                    if (verificationResult.valid)
                    {
                        Console.WriteLine($"Email {email} is valid");
                    }
                    else
                    {
                        Console.WriteLine($"Email {email} is not valid");
                    }
                }
                else
                {
                    Console.WriteLine($"Error verifying email: {response.StatusCode}");
                }
            }
        }
    }

    public class VerificationResult
    {
        public bool valid { get; set; }
        public string message { get; set; }
    }
}

Make sure to replace YOUR_API_KEY with your actual API key from the email verification service you choose to use.