+1 vote

I would like to know if with you library is possible to validate an email address and if it possible to check if exists, contacting the smtp server ?

by

1 Answer

0 votes
 
Best answer

You can check several things with AddressValidator:

1.
Does email address have a valid format:

AddressValidator validator = new AddressValidator();
Assert.AreEqual(
    AddressValidationResult.Success,
    validator.ValidateFormat("email@example.com"));

2.
You can check if specified email has DNS MX record for the address' domain (MX record stores the address of the recipients SMTP server):

Assert.AreEqual(
    AddressValidationResult.Success,
    validator.ValidateMX("email@example.com"));

It also performs format check (1).

3.
Finally AddressValidator tries to connect to SMTP server address found in the MX record.

Then it simulates message relay - it acts like another SMTP server, that tries to send a message to this address.

SmtpRejection means that SMTP server rejected email address.
SmtpError means that SMTP server returned an error.

AddressValidator disconnects before any message data are actually sent.

Assert.AreEqual(
    AddressValidationResult.Success,
    validator.Validate"email@example.com"));

It also performs format check (1) and MX check (2).

by (297k points)
edited by
...