34
1
using System;
2
using System.Net;
3
4
class Program {
5
static void Main(string[] args) {
6
string email = "myemail@email.com";
7
bool isValid = isValidEmailDomain(email);
8
Console.WriteLine($"Is {email} a valid email? {isValid}");
9
}
10
11
static bool isValidEmailDomain(string email) {
12
if (string.IsNullOrWhiteSpace(email)) {
13
return false;
14
}
15
16
string[] parts = email.Split('@');
17
if (parts.Length != 2) {
18
return false; // email must have exactly one @ symbol
19
}
20
21
string localPart = parts[0];
22
string domainPart = parts[1];
23
24
try {
25
// check if domain name has a valid MX record
26
var hostEntry = Dns.GetHostEntry(domainPart);
27
return hostEntry.HostName.Length > 0;
28
}
29
catch {
30
return false; // domain name is invalid or does not have a valid MX record
31
}
32
}
33
}
34
Cached Result
Въведи време:
>