code: def smtp_connection(c):
      
      if c.smtp_ssl:
          klass = smtplib.SMTP_SSL
      else:
          klass = smtplib.SMTP
      conn = klass(c.smtp_host, c.smtp_port, timeout=c.smtp_timeout)
      if not c.smtp_ssl:
          conn.ehlo()
          conn.starttls()
          conn.ehlo()
      if c.smtp_username:
          conn.login(c.smtp_username, c.smtp_password)
      return conn
docs: Create an SMTP connection from a Config object