Smtp |
[SerializableAttribute] public class SmtpCommandException : CommandException
The SmtpCommandException type exposes the following members.
| Name | Description | |
|---|---|---|
| SmtpCommandException(SerializationInfo, StreamingContext) | Obsolete. Initializes a new instance of the SmtpCommandException class. | |
| SmtpCommandException(SmtpErrorCode, SmtpStatusCode, String) | Initializes a new instance of the SmtpCommandException class. | |
| SmtpCommandException(SmtpErrorCode, SmtpStatusCode, MailboxAddress, String) | Initializes a new instance of the SmtpCommandException class. | |
| SmtpCommandException(SmtpErrorCode, SmtpStatusCode, String, Exception) | Initializes a new instance of the SmtpCommandException class. | |
| SmtpCommandException(SmtpErrorCode, SmtpStatusCode, MailboxAddress, String, Exception) | Initializes a new instance of the SmtpCommandException class. |
| Name | Description | |
|---|---|---|
| Data | (Inherited from Exception) | |
| ErrorCode | Get the error code which may provide additional information. | |
| HelpLink | (Inherited from Exception) | |
| HResult | (Inherited from Exception) | |
| InnerException | (Inherited from Exception) | |
| Mailbox | Get the mailbox that the error occurred on. | |
| Message | (Inherited from Exception) | |
| Source | (Inherited from Exception) | |
| StackTrace | (Inherited from Exception) | |
| StatusCode | Get the status code returned by the SMTP server. | |
| TargetSite | (Inherited from Exception) |
| Name | Description | |
|---|---|---|
| Equals | (Inherited from Object) | |
| Finalize | (Inherited from Object) | |
| GetBaseException | (Inherited from Exception) | |
| GetHashCode | (Inherited from Object) | |
| GetObjectData |
When overridden in a derived class, sets the SerializationInfo
with information about the exception.
(Overrides ExceptionGetObjectData(SerializationInfo, StreamingContext)) | |
| GetType | (Inherited from Exception) | |
| MemberwiseClone | (Inherited from Object) | |
| ToString | (Inherited from Exception) |
| Name | Description | |
|---|---|---|
| SerializeObjectState | (Inherited from Exception) |
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); } }