Skip to content

Instantly share code, notes, and snippets.

@johnw86
Created May 25, 2018 10:54
Show Gist options
  • Save johnw86/db4b1afdab22c6b7577fc7cd40136de1 to your computer and use it in GitHub Desktop.
Save johnw86/db4b1afdab22c6b7577fc7cd40136de1 to your computer and use it in GitHub Desktop.
Email validator
using System;
using System.IO;
using System.Net.Mail;
namespace EmailValidator
{
class Program
{
static void Main()
{
var emails = File.ReadAllLines("emails.txt");
for (var i = 0; i < emails.Length; i++)
{
var email = emails[i];
try
{
new MailAddress(email);
}
catch (FormatException)
{
Console.WriteLine($"Invalid email address: {email}, line number: {i}");
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment