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.

To authenticate with Google SMTP using an Okta session token, first exchange the Okta token for a Google OAuth 2.0 token. Then, use this OAuth token for SMTP authentication by setting it in the xoauth2 mechanism within your email client configuration. If you want to skip all these steps, contact SMTP service providers like SMTPget or Mailgun. They will handle everything for you.

SMTPget is the best digital marketing agency providing all the services in best price

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.