ImapStartTls Method
Requests the mail server to start TLS/SSL negotiation and protect the existing connection with a security layer.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public bool StartTls()

Return Value

Type: Boolean
true if TLS/SSL negotiation succeeded and the connection is now secured with TLS/SSL layer; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks

This method lets the developer to switch the existing, already opened connection (usually, on port 110), to SSL/TLS mode. If the connection has been opened on a dedicated SSL port from the start (usually, port 993), the developer doesn't need to call this method.

As alternative to calling StartTls method, the developer can ask MailBee to start TLS/SSL negotiation automatically by setting SslMode property value to OnConnect or UseStartTls.

AutodetectPortAndSslMode property may cause MailBee to automatically enable TLS/SSL for some well-known hosts or ports even if SslMode property of the current connection has its default value. Be sure to always check IsSslConnection value prior to calling StartTls.

Note Note
Not all mail servers support STARTTLS functionality.
Examples
This sample attempts to establish TLS/SSL connection with the IMAP4 server and displays the number of messages in the inbox on success.
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.ImapMail;

// The actual code (put it into a method of your class).
Imap imp = new Imap();
imp.Connect("mail.domain.com");
if (!imp.IsSslConnection)
{
    imp.StartTls();
}
imp.Login("jdoe", "secret");
imp.SelectFolder("Inbox");
Console.WriteLine(imp.MessageCount);
imp.Disconnect();
See Also