public async Task <EmailValidationResult> VerifyEmailAddress(string emailAddress) { //basic validation first if (string.IsNullOrWhiteSpace(emailAddress) || _regex.Match(emailAddress).Length == 0) { return(new EmailValidationResult(emailAddress)); } //now get the domain var domain = emailAddress.Substring(emailAddress.IndexOf('@') + 1); try { await Dns.GetHostEntryAsync(domain).ConfigureAwait(false); var mxResponse = await Dns.QueryAsync(domain, QType.MX).ConfigureAwait(false); return(new EmailValidationResult(emailAddress, true, true, mxResponse.RecordsMX.Any())); } catch (SocketException) { return(new EmailValidationResult(emailAddress, true)); } catch (AggregateException ex) { if (ex.InnerException is SocketException) { return(new EmailValidationResult(emailAddress, true)); } throw; } }