startTls method

Future<SmtpResponse> startTls()

Upgrades the current insure connection to SSL.

Opportunistic TLS (Transport Layer Security) refers to extensions in plain text communication protocols, which offer a way to upgrade a plain text connection to an encrypted (TLS or SSL) connection instead of using a separate port for encrypted communication.

Implementation

Future<SmtpResponse> startTls() async {
  final response = await sendCommand(SmtpStartTlsCommand());
  if (!response.isOkStatus) {
    // sendCommand already fails 4xx/5xx replies, this guards the rest
    throw SmtpException(this, response);
  }
  log('STARTTLS: upgrading socket to secure one...', initial: 'A');
  await upgradeToSslSocket();
  await ehlo();

  return response;
}