How to authenticate with google smtp after receiving okta session token?

i programmatically login into okta and upon success i get a reponse:

{'expiresAt': '2024-04-23T02:23:12.000Z',
 'status': 'SUCCESS',
 'sessionToken': 'MY SESSION_TOKEN,
 '_embedded': {'user': {'id': 'MY_USER_ID',
   'passwordChanged': '2023-12-03T18:00:39.000Z',
   'profile': {'login': 'MY_OKTA_LOGIN',
    'firstName': 'FIRST NAME',
    'lastName': 'LAST NAME',
    'locale': 'en_US',
    'timeZone': 'America/Los_Angeles'}}},
 '_links': {'cancel': {'href': 'https://myfirm.okta.com/api/v1/authn/cancel',
   'hints': {'allow': ['POST']}}}}

Then i can hopefully somehow use the session token to login into gmail to send some email

 smtp = smtplib.SMTP('smtp.gmail.com', 587)
    # smtp_server = smtplib.SMTP(server, port) # smtplib.SMTP_SSL('smtp.gmail.com', 465)
    
    smtp.ehlo()
    if use_tls:
        smtp.starttls()
    smtp.ehlo()
    smtp.login(username, password)

what value should i pass for user name and password ?

To authenticate with Google SMTP after obtaining an Okta session token:

  1. Obtain the Okta session token by authenticating with Okta.
  2. Exchange the Okta token for an OAuth access token compatible with Google SMTP.
  3. Use the OAuth access token to authenticate with Google SMTP.
  4. Send emails using Google SMTP.

If you want to skip all these steps, contact with smtp server service providers like SMTPget, iDealSMTP, or SendGrid. They will do all these things for you.