Verify an Email Address using C#
Due to the variety of sources an email address can originate from, it is a key security measure to ensure that it is not part of a phishing attempt, malware, or other form of cyberattack. Leveraging the following API, you can verify the validity of an email address, therefore preventing any malicious advances against your organization. The validation process will also check for any syntax errors that may cause miscommunication with an otherwise harmless email address.
To begin, we will need to install the .NET Core SDK:
Install-Package Cloudmersive.APIClient.NETCore.Validate -Version 2.0.2
After the client software is installed, you will input the email address you want to validate, and call the function with the following code:
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NETCore.Validate.Api;
using Cloudmersive.APIClient.NETCore.Validate.Client;
using Cloudmersive.APIClient.NETCore.Validate.Model;namespace Example
{
public class EmailFullValidationExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");var apiInstance = new EmailApi();
var email = email_example; // string | Email address to validate, e.g. \"support@cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.try
{
// Fully validate an email address
FullEmailValidationResponse result = apiInstance.EmailFullValidation(email);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling EmailApi.EmailFullValidation: " + e.Message );
}
}
}
}
So is the address valid or invalid? The API has reached out to the server behind the scenes to provide an answer to your question in the returned response.