---
id: object/codeunit/5321
type: object
title: Codeunit 5321 "Exchange Web Services Server"
summary: Codeunit 5321 "Exchange Web Services Server" in Base Application (System.Integration). 23 public procedures, 3 events. Present since at least BC23, still in BC30, changed in BC25, BC28.
tier: official
language: en
tags:
  - codeunit
  - base application
versions:
  introduced: null
  last_changed: "28"
  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: 1a4c22bd28b920a0663228f4b7ce2d7cf601899cacb91bb4594f04c96096ae0a
evidence:
  - kind: code
    url: https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/System/Exchange/ExchangeWebServicesServer.Codeunit.al
    title: src/Layers/W1/BaseApp/System/Exchange/ExchangeWebServicesServer.Codeunit.al (releases/29.x)
    date: null
    commit: ea08af5ef2d6a9b5c5af4a029288abbe2c883220
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
object_type: codeunit
object_id: 5321
name: Exchange Web Services Server
namespace: System.Integration
app: Base Application
extends: null
first_version: "23"
last_version: "30"
present_in:
  - "23"
  - "24"
  - "25"
  - "26"
  - "27"
  - "28"
  - "29"
  - "30"
changed_in:
  - "25"
  - "28"
source_major: "29"
obsolete: null
countries: []
ms_search_form_ids: []
counts:
  fields: 0
  procedures: 30
  events: 3
  subscribers: 0
relations:
  out: 0
  referenced_by: 0
  pages: 0
  extended_by: 0
  event_subscribers: 0
  calls: 2
  called_by: 5
  implements: 0
---

# Codeunit 5321 "Exchange Web Services Server"

> Codeunit 5321 "Exchange Web Services Server" in Base Application (System.Integration). 23 public procedures, 3 events. Present since at least BC23, still in BC30, changed in BC25, BC28.

Base Application · System.Integration · BC23-30 · [source at ea08af5e](https://github.com/microsoft/BCApps/blob/ea08af5ef2d6a9b5c5af4a029288abbe2c883220/src/Layers/W1/BaseApp/System/Exchange/ExchangeWebServicesServer.Codeunit.al) · facts from BC29

## Events published

- `OnBeforeSaveHTMLEmailToInbox(var EmailSubject: Text; var EmailBodyHTML: Text; var SenderAddress: Text; var SenderName: Text; var RecipientAddress: Text)` (integration)
- `OnBeforeSendEmailMessageWithAttachment(var Subject: Text; var RecipientAddress: Text; var BodyHTML: Text; var SenderAddress: Text)` (integration)
- `OnAfterGetProdEndpoint(var ProdEndPointText: Text)` (integration)

## Procedures

- `Initialize(AutodiscoveryEmail: Text[250]; ServiceUri: Text; Credentials: DotNet ExchangeCredentials; Rediscover: Boolean): Boolean`
- `InitializeAndValidate(AutodiscoveryEmail: Text[250]; var ServiceUri: Text; Credentials: DotNet ExchangeCredentials): Boolean`
- `Initialize2010(AutodiscoveryEmail: Text[250]; ServiceUri: Text; Credentials: DotNet ExchangeCredentials; Rediscover: Boolean): Boolean`
- `Initialize2010WithUserImpersonation(AutodiscoveryEmail: Text[250]; ServiceUri: Text; Credentials: DotNet ExchangeCredentials; Rediscover: Boolean): Boolean`
- `InitializeWithCertificate(ApplicationID: Guid; Thumbprint: Text[40]; AuthenticationEndpoint: Text[250]; ExchangeEndpoint: Text[250]; ResourceUri: Text[250])`
- `InitializeWithOAuthToken(Token: SecretText; ExchangeEndpoint: Text)`
- `ValidCredentials()`
- `SetImpersonatedIdentity(Email: Text[250])`
- `InstallApp(ManifestPath: InStream)`
- `CreateAppointment(var Appointment: DotNet IAppointment)`
- `SendEmailMessageWithAttachment(Subject: Text; RecipientAddress: Text; BodyHTML: Text; AttachmentPath: Text; SenderAddress: Text)`
- `SaveEmailToInbox(EmailMessage: Text)`
- `SaveHTMLEmailToInbox(EmailSubject: Text; EmailBodyHTML: Text; SenderAddress: Text; SenderName: Text; RecipientAddress: Text)`
- `GetEmailFolder(FolderId: Text; var Folder: DotNet IEmailFolder): Boolean`
- `IdenticalMailExists(SampleMessage: DotNet IEmailMessage; TargetFolder: DotNet IEmailFolder; var TargetMessage: DotNet IEmailMessage): Boolean`
- `CompareEmailAttachments(LeftMsg: DotNet IEmailMessage; RightMsg: DotNet IEmailMessage): Boolean`
- `GetEmailAndAttachments(ItemID: Text[250]; var TempExchangeObject: Record "Exchange Object" temporary; Action: Option InitiateSendToOCR,InitiateSendToIncomingDocuments,InitiateSendToWorkFlow,IntiateSendToAttachments; RecRef: RecordRef)` (obsolete 28.0: Please use Microsoft Graph API instead e.g `Email - Outlook REST API`)
- `GetEmailBody(ItemID: Text[250]): Text` (obsolete 28.0: Please use Microsoft Graph API instead e.g `Email - Outlook REST API`)
- `EmailHasAttachments(ItemID: Text[250]): Boolean` (obsolete 28.0: Please use Microsoft Graph API instead e.g `Email - Outlook REST API`)
- `GetEndpoint(): Text`
- `ProdEndpoint(): Text`
- `IsDefaultProdEndpoint(Endpoint: Text): Boolean`
- `GetCurrentUserTimeZone(): Text`

Plus 4 local procedures.

## Triggers

OnRun

## 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) (1 call: `InitializeWithOAuthToken → CreateExchangeServiceWrapperWithToken`)
- [Codeunit 6303 "Azure AD Auth Flow"](../codeunit/6303.md) (1 call: `ValidCredentials → CanHandle`)

## Called by

- [Codeunit 5323 "Exchange Add-in Setup"](../codeunit/5323.md) (10 calls: `DeployAddin → InstallApp`, `DeploySampleEmails → SaveHTMLEmailToInbox`, `ImpersonateUser → SetImpersonatedIdentity`, …)
- [Codeunit 5052 "AttachmentManagement"](../codeunit/5052.md) (6 calls: `InitializeExchangeWithToken → GetEndpoint`, `InitializeExchangeWithToken → InitializeWithCertificate`, `InitializeExchangeWithToken → InitializeWithOAuthToken`, …)
- [Table 5080 "To-do"](../table/5080.md) (6 calls: `Initialize → GetEndpoint`, `Initialize → InitializeWithCertificate`, `Initialize → InitializeWithOAuthToken`, …)
- [Table 6700 "Exchange Sync"](../table/6700.md) (2 calls: `GetExchangeEndpoint → GetEndpoint`, `GetExchangeEndpoint → IsDefaultProdEndpoint`)
- [Codeunit 6700 "O365 Sync. Management"](../codeunit/6700.md) (1 call: `ValidateExchangeConnection → InitializeAndValidate`)

## Across versions

- Present in: BC23-30
- Changed (declaration) in: BC25, BC28

## Deprecations

- procedure EmailHasAttachments: Pending 28.0 (#if not CLEAN28), "Please use Microsoft Graph API instead e.g `Email - Outlook REST API`"
- procedure GetEmailAndAttachments: Pending 28.0 (#if not CLEAN28), "Please use Microsoft Graph API instead e.g `Email - Outlook REST API`"
- procedure GetEmailBody: Pending 28.0 (#if not CLEAN28), "Please use Microsoft Graph API instead e.g `Email - Outlook REST API`"
- procedure TryEmailHasAttachments: Pending 28.0 (#if not CLEAN28), "Please use Microsoft Graph API instead e.g `Email - Outlook REST API`"
- procedure TryGetEmailWithAttachments: Pending 28.0 (#if not CLEAN28), "Please use Microsoft Graph API instead e.g `Email - Outlook REST API`"

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: "Exchange Web Services Server")`, then `bcatlas_get_procedure_body` or `bcatlas_get_neighbors` on the returned id.
