Click or drag to resize
MimeKit

SmtpClientVerifyAsync Method

Asynchronously verify the existence of a mailbox address.

Namespace: MailKit.Net.Smtp
Assembly: MailKit (in MailKit.dll) Version: 4.7.1
Syntax
C#
public Task<MailboxAddress> VerifyAsync(
	string address,
	CancellationToken cancellationToken = default
)

Parameters

address  String
The mailbox address.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Return Value

TaskMailboxAddress
The expanded mailbox address.

Implements

ISmtpClientVerifyAsync(String, CancellationToken)
Exceptions
ExceptionCondition
ArgumentNullExceptionaddress is null.
ArgumentExceptionaddress is an empty string.
ObjectDisposedException The SmtpClient has been disposed.
ServiceNotConnectedException The SmtpClient is not connected.
ServiceNotAuthenticatedException Authentication is required before verifying the existence of an address.
OperationCanceledException The operation has been canceled.
IOException An I/O error occurred.
SmtpCommandException The SMTP command failed.
SmtpProtocolException An SMTP protocol exception occurred.
Remarks
Verifies the existence a mailbox address with the SMTP server, returning the expanded mailbox address if it exists.
Example
C#
public static void VerifyAddress ()
{
    using (var client = new SmtpClient ()) {
        client.Connect ("smtp.mail-server.com", 465, SecureSocketOptions.SslOnConnect);
        client.Authenticate ("username", "password");

        try {
            var verified = client.Verify ("smith");
            Console.WriteLine ($"'smith' was resolved the the following mailbox: {verified}");
        } catch (SmtpCommandException ex) {
            Console.WriteLine ($"'smith' is not a valid address: {ex.Message}");
        }

        client.Disconnect (true);
    }
}
See Also