I’ve noticed that if you try to send an email to an invalid address, an exception is raised:
MailAddress To=new MailAddress("invalidemailaddress","recipientname");
throws:
"The specified string is not in the form required for an e-mail address"
This means that there must be a .Net function which is executed in MailAddress to check if the email address is valid or not. Is there a way to call this ‘validate’ function directly? This way I won’t need to create my own IsValid function.
Yes, there is such a .Net function, but its functionality is unaccessible by “standard” means: MailAdress uses a private
ParseAddressmethod, which in turn usesSystem.Net.Mime.MailBnfHelper. The latter is aninternalclass, so it’s not (easily) accessible outside the framework itself.Thus, the only way to use these functions would be to use reflection, which I strongly advise against. Since these functions are undocumented and unaccessible without reflection, their implementation might change and your code might break in future versions of the framework.