code: def _get_smtp_connection(
      host: str, port: int, timeout: int, with_ssl: bool
  ) -> smtplib.SMTP:
      """
      Return an SMTP connection to the specified host and port, with optional SSL encryption.
  
      :param host: The hostname or IP address of the SMTP server.
      :param port: The port number to connect to on the SMTP server.
      :param timeout: The timeout in seconds for the connection.
      :param with_ssl: Whether to use SSL encryption for the connection.
      :return: An SMTP connection to the specified host and port.
      """
      if not with_ssl:
          return smtplib.SMTP(host=host, port=port, timeout=timeout)
      else:
          ssl_context_string = conf.get("email", "SSL_CONTEXT")
          if ssl_context_string == "default":
              ssl_context = ssl.create_default_context()
          elif ssl_context_string == "none":
              ssl_context = None
          else:
              raise RuntimeError(
                  f"The email.ssl_context configuration variable must "
                  f"be set to 'default' or 'none' and is '{ssl_context_string}."
              )
          return smtplib.SMTP_SSL(
              host=host, port=port, timeout=timeout, context=ssl_context
          )
  
imports: from __future__ import annotations
  import collections.abc
  import logging
  import os
  import smtplib
  import ssl
  import warnings
  from email.mime.application import MIMEApplication
  from email.mime.multipart import MIMEMultipart
  from email.mime.text import MIMEText
  from email.utils import formatdate
  from typing import Any, Iterable
  import re2
  from airflow.configuration import conf
  from airflow.exceptions import AirflowConfigException, AirflowException, RemovedInAirflow3Warning
label_desc: Use image node_id 6 for calling a global function with example usage: _get_smtp_connection(host, port, timeout, with_ssl) and returns: smtplib, smtplib