Smtp |
public class SmtpClient : MailTransport, ISmtpClient, IMailTransport, IMailService, IDisposable
The SmtpClient type exposes the following members.
Name | Description | |
---|---|---|
SmtpClient | Initializes a new instance of the SmtpClient class. | |
SmtpClient(IProtocolLogger) | Initializes a new instance of the SmtpClient class. |
Name | Description | |
---|---|---|
AuthenticationMechanisms |
Get the authentication mechanisms supported by the SMTP server.
(Overrides MailServiceAuthenticationMechanisms) | |
Capabilities | Get the capabilities supported by the SMTP server. | |
CheckCertificateRevocation |
Get or set whether connecting via SSL/TLS should check certificate revocation.
(Inherited from MailService) | |
ClientCertificates |
Get or set the client SSL certificates.
(Inherited from MailService) | |
DeliveryStatusNotificationType | Get or set how much of the message to include in any failed delivery status notifications. | |
IsAuthenticated |
Get whether or not the client is currently authenticated with the SMTP server.
(Overrides MailServiceIsAuthenticated) | |
IsConnected |
Get whether or not the client is currently connected to an SMTP server.
(Overrides MailServiceIsConnected) | |
IsEncrypted |
Get whether or not the connection is encrypted (typically via SSL or TLS).
(Overrides MailServiceIsEncrypted) | |
IsSecure |
Get whether or not the connection is secure (typically via SSL or TLS).
(Overrides MailServiceIsSecure) | |
IsSigned |
Get whether or not the connection is signed (typically via SSL or TLS).
(Overrides MailServiceIsSigned) | |
LocalDomain | Get or set the local domain. | |
LocalEndPoint |
Get or set the local IP end point to use when connecting to the remote host.
(Inherited from MailService) | |
MaxSize | Get the maximum message size supported by the server. | |
PreferSendAsBinaryData | Get whether or not the BDAT command is preferred over the DATA command. | |
Protocol |
Get the protocol supported by the message service.
(Overrides MailServiceProtocol) | |
ProtocolLogger |
Get the protocol logger.
(Inherited from MailService) | |
ProxyClient |
Get or set the proxy client to use when connecting to a remote host.
(Inherited from MailService) | |
RequireTLS | Get or set whether the client should use the REQUIRETLS extension if it is available. | |
ServerCertificateValidationCallback |
Get or set a callback function to validate the server certificate.
(Inherited from MailService) | |
SslCipherAlgorithm |
Get the negotiated SSL or TLS cipher algorithm.
(Overrides MailServiceSslCipherAlgorithm) | |
SslCipherStrength |
Get the negotiated SSL or TLS cipher algorithm strength.
(Overrides MailServiceSslCipherStrength) | |
SslHashAlgorithm |
Get the negotiated SSL or TLS hash algorithm.
(Overrides MailServiceSslHashAlgorithm) | |
SslHashStrength |
Get the negotiated SSL or TLS hash algorithm strength.
(Overrides MailServiceSslHashStrength) | |
SslKeyExchangeAlgorithm |
Get the negotiated SSL or TLS key exchange algorithm.
(Overrides MailServiceSslKeyExchangeAlgorithm) | |
SslKeyExchangeStrength |
Get the negotiated SSL or TLS key exchange algorithm strength.
(Overrides MailServiceSslKeyExchangeStrength) | |
SslProtocol |
Get the negotiated SSL or TLS protocol version.
(Overrides MailServiceSslProtocol) | |
SslProtocols |
Get or set the set of enabled SSL and/or TLS protocol versions that the client is allowed to use.
(Inherited from MailService) | |
SyncRoot |
Gets an object that can be used to synchronize access to the SMTP server.
(Overrides MailServiceSyncRoot) | |
Timeout |
Get or set the timeout for network streaming operations, in milliseconds.
(Overrides MailServiceTimeout) |
Name | Description | |
---|---|---|
Authenticate(ICredentials, CancellationToken) |
Authenticate using the supplied credentials.
(Inherited from MailService) | |
Authenticate(SaslMechanism, CancellationToken) |
Authenticate using the specified SASL mechanism.
(Overrides MailServiceAuthenticate(SaslMechanism, CancellationToken)) | |
Authenticate(Encoding, ICredentials, CancellationToken) |
Authenticate using the supplied credentials.
(Overrides MailServiceAuthenticate(Encoding, ICredentials, CancellationToken)) | |
Authenticate(String, String, CancellationToken) |
Authenticate using the specified user name and password.
(Inherited from MailService) | |
Authenticate(Encoding, String, String, CancellationToken) |
Authenticate using the specified user name and password.
(Inherited from MailService) | |
AuthenticateAsync(ICredentials, CancellationToken) |
Asynchronously authenticate using the supplied credentials.
(Inherited from MailService) | |
AuthenticateAsync(SaslMechanism, CancellationToken) |
Asynchronously authenticate using the specified SASL mechanism.
(Overrides MailServiceAuthenticateAsync(SaslMechanism, CancellationToken)) | |
AuthenticateAsync(Encoding, ICredentials, CancellationToken) |
Asynchronously authenticate using the supplied credentials.
(Overrides MailServiceAuthenticateAsync(Encoding, ICredentials, CancellationToken)) | |
AuthenticateAsync(String, String, CancellationToken) |
Asynchronously authenticate using the specified user name and password.
(Inherited from MailService) | |
AuthenticateAsync(Encoding, String, String, CancellationToken) |
Asynchronously authenticate using the specified user name and password.
(Inherited from MailService) | |
Connect(Uri, CancellationToken) |
Establish a connection to the specified mail server.
(Inherited from MailService) | |
Connect(String, Int32, Boolean, CancellationToken) |
Establish a connection to the specified mail server.
(Inherited from MailService) | |
Connect(String, Int32, SecureSocketOptions, CancellationToken) |
Establish a connection to the specified SMTP or SMTP/S server.
(Overrides MailServiceConnect(String, Int32, SecureSocketOptions, CancellationToken)) | |
Connect(Socket, String, Int32, SecureSocketOptions, CancellationToken) |
Establish a connection to the specified SMTP or SMTP/S server using the provided socket.
(Overrides MailServiceConnect(Socket, String, Int32, SecureSocketOptions, CancellationToken)) | |
Connect(Stream, String, Int32, SecureSocketOptions, CancellationToken) |
Establish a connection to the specified SMTP or SMTP/S server using the provided stream.
(Overrides MailServiceConnect(Stream, String, Int32, SecureSocketOptions, CancellationToken)) | |
ConnectAsync(Uri, CancellationToken) |
Asynchronously establish a connection to the specified mail server.
(Inherited from MailService) | |
ConnectAsync(String, Int32, Boolean, CancellationToken) |
Asynchronously establish a connection to the specified mail server.
(Inherited from MailService) | |
ConnectAsync(String, Int32, SecureSocketOptions, CancellationToken) |
Asynchronously establish a connection to the specified SMTP or SMTP/S server.
(Overrides MailServiceConnectAsync(String, Int32, SecureSocketOptions, CancellationToken)) | |
ConnectAsync(Socket, String, Int32, SecureSocketOptions, CancellationToken) |
Asynchronously establish a connection to the specified SMTP or SMTP/S server using the provided socket.
(Overrides MailServiceConnectAsync(Socket, String, Int32, SecureSocketOptions, CancellationToken)) | |
ConnectAsync(Stream, String, Int32, SecureSocketOptions, CancellationToken) |
Asynchronously establish a connection to the specified SMTP or SMTP/S server using the provided socket.
(Overrides MailServiceConnectAsync(Stream, String, Int32, SecureSocketOptions, CancellationToken)) | |
Disconnect |
Disconnect the service.
(Overrides MailServiceDisconnect(Boolean, CancellationToken)) | |
DisconnectAsync |
Asynchronously disconnect the service.
(Overrides MailServiceDisconnectAsync(Boolean, CancellationToken)) | |
Dispose |
Releases all resource used by the MailService object.
(Inherited from MailService) | |
Dispose(Boolean) |
Releases the unmanaged resources used by the SmtpClient and
optionally releases the managed resources.
(Overrides MailServiceDispose(Boolean)) | |
Equals | (Inherited from Object) | |
Expand | Expand a mailing address alias. | |
ExpandAsync | Asynchronously expand a mailing address alias. | |
Finalize |
Releases unmanaged resources and performs other cleanup operations before the
MailService is reclaimed by garbage collection.
(Inherited from MailService) | |
GetDeliveryStatusNotifications | Get the types of delivery status notification desired for the specified recipient mailbox. | |
GetEnvelopeId | Get the envelope identifier to be used with delivery status notifications. | |
GetHashCode | (Inherited from Object) | |
GetSize | Get the size of the message. | |
GetSizeAsync | Asynchronously get the size of the message. | |
GetType | (Inherited from Object) | |
MemberwiseClone | (Inherited from Object) | |
NoOp |
Ping the SMTP server to keep the connection alive.
(Overrides MailServiceNoOp(CancellationToken)) | |
NoOpAsync |
Asynchronously ping the SMTP server to keep the connection alive.
(Overrides MailServiceNoOpAsync(CancellationToken)) | |
OnAuthenticated |
Raise the authenticated event.
(Inherited from MailService) | |
OnConnected |
Raise the connected event.
(Inherited from MailService) | |
OnDisconnected |
Raise the disconnected event.
(Inherited from MailService) | |
OnMessageSent |
Raise the message sent event.
(Inherited from MailTransport) | |
OnNoRecipientsAccepted | Invoked only when no recipients were accepted by the SMTP server. | |
OnRecipientAccepted | Invoked when a recipient is accepted by the SMTP server. | |
OnRecipientNotAccepted | Invoked when a recipient is not accepted by the SMTP server. | |
OnSenderAccepted | Invoked when the sender is accepted by the SMTP server. | |
OnSenderNotAccepted | Invoked when a recipient is not accepted by the SMTP server. | |
Prepare | Prepare the message for transport with the specified constraints. | |
Send(MimeMessage, CancellationToken, ITransferProgress) |
Send the specified message.
(Inherited from MailTransport) | |
Send(FormatOptions, MimeMessage, CancellationToken, ITransferProgress) |
Send the specified message.
(Overrides MailTransportSend(FormatOptions, MimeMessage, CancellationToken, ITransferProgress)) | |
Send(MimeMessage, MailboxAddress, IEnumerableMailboxAddress, CancellationToken, ITransferProgress) |
Send the specified message using the supplied sender and recipients.
(Inherited from MailTransport) | |
Send(FormatOptions, MimeMessage, MailboxAddress, IEnumerableMailboxAddress, CancellationToken, ITransferProgress) |
Send the specified message using the supplied sender and recipients.
(Overrides MailTransportSend(FormatOptions, MimeMessage, MailboxAddress, IEnumerableMailboxAddress, CancellationToken, ITransferProgress)) | |
SendAsync(MimeMessage, CancellationToken, ITransferProgress) |
Asynchronously send the specified message.
(Inherited from MailTransport) | |
SendAsync(FormatOptions, MimeMessage, CancellationToken, ITransferProgress) |
Asynchronously send the specified message.
(Overrides MailTransportSendAsync(FormatOptions, MimeMessage, CancellationToken, ITransferProgress)) | |
SendAsync(MimeMessage, MailboxAddress, IEnumerableMailboxAddress, CancellationToken, ITransferProgress) |
Asynchronously send the specified message using the supplied sender and recipients.
(Inherited from MailTransport) | |
SendAsync(FormatOptions, MimeMessage, MailboxAddress, IEnumerableMailboxAddress, CancellationToken, ITransferProgress) |
Asynchronously send the specified message using the supplied sender and recipients.
(Overrides MailTransportSendAsync(FormatOptions, MimeMessage, MailboxAddress, IEnumerableMailboxAddress, CancellationToken, ITransferProgress)) | |
SendCommand | Send a custom command to the SMTP server. | |
SendCommandAsync | Asynchronously send a custom command to the SMTP server. | |
ToString | (Inherited from Object) | |
Verify | Verify the existence of a mailbox address. | |
VerifyAsync | Asynchronously verify the existence of a mailbox address. |
Name | Description | |
---|---|---|
Authenticated |
Occurs when the client has been successfully authenticated.
(Inherited from MailService) | |
Connected |
Occurs when the client has been successfully connected.
(Inherited from MailService) | |
Disconnected |
Occurs when the client gets disconnected.
(Inherited from MailService) | |
MessageSent |
Occurs when a message is successfully sent via the transport.
(Inherited from MailTransport) |
The SmtpClient class supports both the "smtp" and "smtps" protocols. The "smtp" protocol makes a clear-text connection to the SMTP server and does not use SSL or TLS unless the SMTP server supports the STARTTLS extension. The "smtps" protocol, however, connects to the SMTP server using an SSL-wrapped connection.
The connection established by any of the Connect methods may be re-used if an application wishes to send multiple messages to the same SMTP server. Since connecting and authenticating can be expensive operations, re-using a connection can significantly improve performance when sending a large number of messages to the same SMTP server over a short period of time.
public static void SendMessages (IList<MimeMessage> messages) { using (var client = new SmtpClient ()) { client.Connect ("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect); client.Authenticate ("username", "password"); foreach (var message in messages) { client.Send (message); } client.Disconnect (true); } }