code: def _post_sendgrid_mail(
      mail_data: dict, conn_id: str = "sendgrid_default"
  ) -> None:
      api_key = None
      try:
          conn = BaseHook.get_connection(conn_id)
          api_key = conn.password
      except AirflowException:
          pass
      if api_key is None:
          warnings.warn(
              "Fetching Sendgrid credentials from environment variables will be deprecated in a future "
              "release. Please set credentials using a connection instead.",
              AirflowProviderDeprecationWarning,
              stacklevel=2,
          )
          api_key = os.environ.get("SENDGRID_API_KEY")
      sendgrid_client = sendgrid.SendGridAPIClient(api_key=api_key)
      response = sendgrid_client.client.mail.send.post(
          request_body=mail_data
      )
      # 2xx status code.
      if 200 <= response.status_code < 300:
          log.info(
              "Email with subject %s is successfully sent to recipients: %s",
              mail_data["subject"],
              mail_data["personalizations"],
          )
      else:
          log.error(
              "Failed to send out email with subject %s, status code: %s",
              mail_data["subject"],
              response.status_code,
          )
  
file_path: airflow/airflow/providers/sendgrid/utils/emailer.py
imports: from __future__ import annotations
  import base64
  import logging
  import mimetypes
  import os
  import warnings
  from typing import Iterable, Union
  import sendgrid
  from sendgrid.helpers.mail import Attachment, Category, Content, CustomArg, Email, Mail, MailSettings, Personalization, SandBoxMode
  from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
  from airflow.hooks.base import BaseHook
  from airflow.utils.email import get_email_address_list
label_desc: Use image node_id 2 for calling a global function with example usage: _post_sendgrid_mail(mail_data, conn_id) without return types