---
id: object/codeunit/4516
type: object
title: Codeunit 4516 "OAuth2 SMTP Authentication"
summary: Codeunit 4516 "OAuth2 SMTP Authentication" in Email - SMTP Connector (System.Email). 5 public procedures, 1 event subscribers. Introduced in BC29, still in BC30.
tier: official
language: en
tags:
  - codeunit
  - email - smtp connector
versions:
  introduced: "29"
  last_changed: null
  deprecated: null
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-11T00:31:51.816Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: dcea11b18394d3903d79034974d1fd943b803719c13adf6f1e395f972fcd3c7e
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Apps/W1/Email%20-%20SMTP%20Connector/app/src/Authentication/OAuth2SMTPAuthentication.Codeunit.al
    title: src/Apps/W1/Email - SMTP Connector/app/src/Authentication/OAuth2SMTPAuthentication.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcapps/12140
object_type: codeunit
object_id: 4516
name: OAuth2 SMTP Authentication
namespace: System.Email
app: Email - SMTP Connector
extends: null
first_version: "29"
last_version: "30"
present_in:
  - "29"
  - "30"
changed_in: []
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 8
  events: 0
  subscribers: 1
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 6
  called_by: 1
  implements: 0
---

# Codeunit 4516 "OAuth2 SMTP Authentication"

> Codeunit 4516 "OAuth2 SMTP Authentication" in Email - SMTP Connector (System.Email). 5 public procedures, 1 event subscribers. Introduced in BC29, still in BC30.

Email - SMTP Connector · System.Email · BC29-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Apps/W1/Email%20-%20SMTP%20Connector/app/src/Authentication/OAuth2SMTPAuthentication.Codeunit.al) · facts from BC29

## Properties

| Property | Value |
|---|---|
| Access | Internal |

## Event subscriptions

- OnSMTPOAuth2Authenticate subscribes to Codeunit "SMTP Authentication" OnSMTPOAuth2Authenticate

## Procedures

- `GetOAuth2Credentials(var UserName: Text; var AccessToken: SecretText)` (internal): Provide the credentials to authenticate using OAuth 2.0 for Exchange Online mailboxes.
- `AuthenticateWithOAuth2()` (internal): Authenticate the current user. Disregard the token cache and show the authentication dialog.
- `AuthenticateWithOAuth2CustomAppReg(var SMTPAccount: Record "SMTP Account")` (internal)
- `CheckOAuth2Authentication()` (internal): Verify if the current user is successfully authenticated. If there is token cache, it will be used. Otherwise, the authentication dialog will be shown.
- `GetUserName(AccessToken: SecretText; var UserName: Text)` (internal): Get user's email address by the access token.

Plus 2 local procedures.

## Calls

From the extracted call graph of BC29 (graphify-al on the snapshot checkout): calls whose target is known from a declared type or an `Object::"Name"` argument. Interface dispatch and calls through events are not counted, so the list is not complete.

- [Codeunit 6300 "Azure AD Mgt."](../codeunit/6300.md) (9 calls: `AuthenticateWithOAuth2 → AcquireTokenByAuthorizationCodeAsSecretText`, `AuthenticateWithOAuth2 → GetO365Resource`, `AuthenticateWithOAuth2 → GetO365ResourceName`, …)
- [Codeunit 4513 "SMTP Connector Impl."](../codeunit/4513.md) (2 calls: `OnSMTPOAuth2Authenticate → CheckIfCustomizedSMTPOAuth`, `OnSMTPOAuth2Authenticate → GetO365SmtpServer`)
- [Codeunit 4620 "SMTP Authentication"](../codeunit/4620.md) (2 calls: `OnSMTPOAuth2Authenticate → GetAccountId`, `OnSMTPOAuth2Authenticate → SetOAuth2AuthInfo`)
- [Codeunit 4110 "Base64 Convert"](../codeunit/4110.md) (1 call: `GetUserName → FromBase64`)
- [Codeunit 457 "Environment Information"](../codeunit/457.md) (1 call: `AuthenticateWithOAuth2CustomAppReg → IsOnPrem`)
- [Codeunit 501 "OAuth2"](../codeunit/501.md) (1 call: `AuthenticateWithOAuth2CustomAppReg → RequestClientCredentialsAdminPermissions`)

## Called by

- [Page 4511 "SMTP Account Wizard"](../page/4511.md) (1 call: `AuthenticateWithOAuth2CustomAppReg → AuthenticateWithOAuth2CustomAppReg`)

## Recent changes

- 2026-10-01 [#12140 [Email - SMTP Connector] Fix OAuth Base64URL token parsing](../../changes/bcapps/12140.md) (main, BC30, fix)

## Across versions

- Present in: BC29-30
- Changed (declaration) in: none

Source: AL metadata extracted from the code (names, ids, signatures, properties); no code bodies (D10).

## Ask your agent

Procedure bodies are not stored here (D10). The call sections above are our own, per object, from the BC29 call graph. For a procedure body or the calls of one procedure, ask bc-code-atlas (external, by Stefan Maron, MIT; default corpus w1-28), which the bc-observatory plugin connects: `bcatlas_resolve_node(object_type: "codeunit", object_name: "OAuth2 SMTP Authentication")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
