parameters: (
          to_address: str, subject: str, html_message: str, text_message: str = None
      )
docstring: Helper sends SMTP message
docstring_summary: Helper sends SMTP message
docstring_tokens: Helper sends SMTP message
function: def _send_message(
          to_address: str, subject: str, html_message: str, text_message: str = None
      ):
          """ Helper sends SMTP message """
          from_address = current_app.config["EMAIL_FROM_ADDRESS"]
          if from_address is None:
              raise ValueError("Missing TM_EMAIL_FROM_ADDRESS environment variable")
  
          msg = MIMEMultipart("alternative")
          msg["Subject"] = subject
          msg["From"] = "{} Tasking Manager <{}>".format(
              current_app.config["ORG_CODE"], from_address
          )
          msg["To"] = to_address
  
          # Record the MIME types of both parts - text/plain and text/html.
          part2 = MIMEText(html_message, "html")
          msg.attach(part2)
          if text_message:
              part1 = MIMEText(text_message, "plain")
              msg.attach(part1)
  
          current_app.logger.debug(f"Sending email via SMTP {to_address}")
          if current_app.config["LOG_LEVEL"] == "DEBUG":
              current_app.logger.debug(msg.as_string())
          else:
              sender = SMTPService._init_smtp_client()
              sender.sendmail(from_address, to_address, msg.as_string())
              sender.quit()
          current_app.logger.debug(f"Email sent {to_address}")
function_tokens: def _send_message ( to_address : str , subject : str , html_message : str , text_message : str = None ) : from_address = current_app . config [ "EMAIL_FROM_ADDRESS" ] if from_address is None : raise ValueError ( "Missing TM_EMAIL_FROM_ADDRESS environment variable" ) msg = MIMEMultipart ( "alternative" ) msg [ "Subject" ] = subject msg [ "From" ] = "{} Tasking Manager <{}>" . format ( current_app . config [ "ORG_CODE" ] , from_address ) msg [ "To" ] = to_address # Record the MIME types of both parts - text/plain and text/html. part2 = MIMEText ( html_message , "html" ) msg . attach ( part2 ) if text_message : part1 = MIMEText ( text_message , "plain" ) msg . attach ( part1 ) current_app . logger . debug ( f"Sending email via SMTP {to_address}" ) if current_app . config [ "LOG_LEVEL" ] == "DEBUG" : current_app . logger . debug ( msg . as_string ( ) ) else : sender = SMTPService . _init_smtp_client ( ) sender . sendmail ( from_address , to_address , msg . as_string ( ) ) sender . quit ( ) current_app . logger . debug ( f"Email sent {to_address}" )