Click or drag to resize
MimeKit

SmtpErrorCode Enumeration

An enumeration of the possible error codes that may be reported by a SmtpCommandException.

Namespace:  MailKit.Net.Smtp
Assembly:  MailKit (in MailKit.dll) Version: 2.3.0
Syntax
C#
public enum SmtpErrorCode
Members
  Member nameValueDescription
MessageNotAccepted0 The message was not accepted for delivery. This may happen if the server runs out of available disk space.
SenderNotAccepted1 The sender's mailbox address was not accepted. Check the Mailbox property for the mailbox used as the sender's mailbox address.
RecipientNotAccepted2 A recipient's mailbox address was not accepted. Check the Mailbox property for the particular recipient mailbox that was not acccepted.
UnexpectedStatusCode3 An unexpected status code was returned by the server. For more details, the Message property may provide some additional hints.
Remarks
An enumeration of the possible error codes that may be reported by a SmtpCommandException.
Examples
C#
public static void SendMessage (MimeMessage message)
{
    using (var client = new SmtpClient ()) {
        try {
            client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect);
        } catch (SmtpCommandException ex) {
            Console.WriteLine ("Error trying to connect: {0}", ex.Message);
            Console.WriteLine ("\tStatusCode: {0}", ex.StatusCode);
            return;
        } catch (SmtpProtocolException ex) {
            Console.WriteLine ("Protocol error while trying to connect: {0}", ex.Message);
            return;
        }

        // Note: Not all SMTP servers support authentication, but GMail does.
        if (client.Capabilities.HasFlag (SmtpCapabilities.Authentication)) {
            try {
                client.Authenticate ("username", "password");
            } catch (AuthenticationException ex) {
                Console.WriteLine ("Invalid user name or password.");
                return;
            } catch (SmtpCommandException ex) {
                Console.WriteLine ("Error trying to authenticate: {0}", ex.Message);
                Console.WriteLine ("\tStatusCode: {0}", ex.StatusCode);
                return;
            } catch (SmtpProtocolException ex) {
                Console.WriteLine ("Protocol error while trying to authenticate: {0}", ex.Message);
                return;
            }
        }

        try {
            client.Send (message);
        } catch (SmtpCommandException ex) {
            Console.WriteLine ("Error sending message: {0}", ex.Message);
            Console.WriteLine ("\tStatusCode: {0}", ex.StatusCode);

            switch (ex.ErrorCode) {
            case SmtpErrorCode.RecipientNotAccepted:
                Console.WriteLine ("\tRecipient not accepted: {0}", ex.Mailbox);
                break;
            case SmtpErrorCode.SenderNotAccepted:
                Console.WriteLine ("\tSender not accepted: {0}", ex.Mailbox);
                break;
            case SmtpErrorCode.MessageNotAccepted:
                Console.WriteLine ("\tMessage not accepted.");
                break;
            }
        } catch (SmtpProtocolException ex) {
            Console.WriteLine ("Protocol error while sending message: {0}", ex.Message);
        }

        client.Disconnect (true);
    }
}
See Also