.NET Framework Class Library SmtpClient..::.EnableSsl Property Specify whether the SmtpClient uses Secure Sockets Layer (SSL) to encrypt the connection.
Namespace:
System.Net.Mail
Assembly:
System (in System.dll)

Syntax
Public Property EnableSsl As Boolean
Get
Set
public bool EnableSsl { get; set; }
public:
property bool EnableSsl {
bool get ();
void set (bool value);
}
member EnableSsl : bool with get, set

Remarks
The EnableSsl property specifies whether SSL is used to access the specified SMTP mail server. The default value for this property can also be set in a machine or application configuration file. Any changes made to the EnableSsl property override the configuration file settings. The SmtpClient class only supports the SMTP Service Extension for Secure SMTP over Transport Layer Security as defined in RFC 3207. In this mode, the SMTP session begins on an unencrypted channel, then a STARTTLS command is issued by the client to the server to switch to secure communication using SSL. See RFC 3207 published by the Internet Engineering Task Force (IETF) for more information. An alternate connection method is where an SSL session is established up front before any protocol commands are sent. This connection method is sometimes called SMTP/SSL, SMTP over SSL, or SMTPS and by default uses port 465. This alternate connection method using SSL is not currently supported. You can use ClientCertificates to specify which client certificates should be used to establish the SSL connection. The ServerCertificateValidationCallback allows you to reject the certificate provided by the SMTP server. The SecurityProtocol property allows you to specify the version of the SSL protocol to use. Note |
|---|
If the EnableSsl property is set to true, and the SMTP mail server does not advertise STARTTLS in the response to the EHLO command, then a call to the Send or SendAsync methods will throw an SmtpException. |

Examples
The following code example establishes an SSL connection with the SMTP server and uses the connection to send an email.
public static void CreateTestMessage(string server)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.UseDefaultCredentials = true;
client.EnableSsl = true;
client.Send(message);
}

Version Information
.NET FrameworkSupported in: 4, 3.5, 3.0, 2.0 .NET Framework Client ProfileSupported in: 4, 3.5 SP1

Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

See Also
|
Biblioteca de clases de .NET Framework SmtpClient..::.EnableSsl (Propiedad) Especifique si el objeto SmtpClient utiliza SSL (Secure Sockets Layer) para cifrar la conexión.
Espacio de nombres:
System.Net.Mail
Ensamblado:
System (en System.dll)

Sintaxis
Public Property EnableSsl As Boolean
Get
Set
public bool EnableSsl { get; set; }
public:
property bool EnableSsl {
bool get ();
void set (bool value);
}
member EnableSsl : bool with get, set
Valor de propiedadTipo: System..::.Boolean
Es true si el objeto SmtpClient utiliza SSL; en caso contrario, es false. El valor predeterminado es false.

Comentarios
La propiedad EnableSsl especifica si SSL se usa para tener acceso al servidor de correo de SMTP especificado. El valor predeterminado para esta propiedad también se puede establecer en un archivo de configuración del equipo o de la aplicación. Cualquier cambio realizado a la propiedad EnableSsl invalida los valores de archivo de configuración. La clase SmtpClient sólo admite la extensión de servicio SMTP para SMTP seguro sobre Seguridad de la capa de transporte como se define en RFC 3207. En este modo, la sesión de SMTP comienza en un canal no cifrado, a continuación, el cliente ejecuta un comando STARTTLS al servidor para intercambiar para proteger la comunicación mediante SSL. Vea RFC 3207 publicada por Internet Engineering Task Force (IETF) para obtener más información. Un método de conexión alternativo es donde una sesión de SSL se establece al frente antes de que se envíe cualquier comando de protocolo. Este método de conexión a veces se denomina SMTP/SSL, SMTP sobre SSL o SMTP y de forma predeterminada usa el puerto 465. Actualmente no se admite este método de conexión alternativo usando SSL. Puede utilizar ClientCertificates para especificar los certificados de cliente que deben utilizarse para establecer la conexión SSL. La propiedad ServerCertificateValidationCallback le permite rechazar el certificado proporcionado por el servidor SMTP. La propiedad SecurityProtocol le permite especificar la versión del protocolo SSL que debe utilizarse. Nota |
|---|
Si la propiedad EnableSsl está establecida en true, y el servidor de correo de SMTP no anuncia STARTTLS en la respuesta al comando EHLO, una llamada a los métodos SendAsync u Send producirá SmtpException. |

Ejemplos
En el siguiente ejemplo de código se establece una conexión SSL con el servidor SMTP y se utiliza dicha conexión para enviar un mensaje de correo electrónico.
public static void CreateTestMessage(string server)
{
string to = "jane@contoso.com";
string from = "ben@contoso.com";
MailMessage message = new MailMessage(from, to);
message.Subject = "Using the new SMTP client.";
message.Body = @"Using this new feature, you can send an e-mail message from an application very easily.";
SmtpClient client = new SmtpClient(server);
// Credentials are necessary if the server requires the client
// to authenticate before it will send e-mail on the client's behalf.
client.UseDefaultCredentials = true;
client.EnableSsl = true;
client.Send(message);
}

Información de versión
.NET FrameworkCompatible con: 4, 3.5, 3.0, 2.0 .NET Framework Client ProfileCompatible con: 4, 3.5 SP1

Plataformas
Windows 7, Windows Vista SP1 o posterior, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (no se admite Server Core), Windows Server 2008 R2 (se admite Server Core con SP1 o posterior), Windows Server 2003 SP2
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Vea también
|