# Microsoft.Exchange.WebServices

**Kind:** Service

**Source:** `Pams/Logic/Pams.Email/Pams.Email.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

`Microsoft.Exchange.WebServices` is a NuGet package dependency in `Pams.Email.csproj` that provides the Exchange Web Services client API. The Pams.Email component uses it to connect to Microsoft Exchange, authenticate requests, and read or send email data through EWS.

## Diagram

```mermaid
flowchart LR
  PamsEmail[Pams.Email] --> EwsPackage[Microsoft.Exchange.WebServices]
  EwsPackage --> EwsClient[ExchangeService Client]
  EwsClient --> Exchange[Microsoft Exchange EWS Endpoint]
  Exchange --> Mailbox[Mailbox Data]
```

## Usage

```ts
const ewsEndpoint = process.env.EXCHANGE_EWS_URL;
const accessToken = process.env.EXCHANGE_ACCESS_TOKEN;

async function getInboxMessages() {
  const response = await fetch(`${ewsEndpoint}/EWS/Exchange.asmx`, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "Content-Type": "text/xml; charset=utf-8",
      SOAPAction:
        "http://schemas.microsoft.com/exchange/services/2006/messages/FindItem",
    },
    body: `<?xml version="1.0" encoding="utf-8"?>
      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                     xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
        <soap:Body>
          <FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
                    Traversal="Shallow">
            <ItemShape>
              <t:BaseShape>IdOnly</t:BaseShape>
            </ItemShape>
            <ParentFolderIds>
              <t:DistinguishedFolderId Id="inbox" />
            </ParentFolderIds>
          </FindItem>
        </soap:Body>
      </soap:Envelope>`,
  });

  if (!response.ok) {
    throw new Error(`EWS request failed: ${response.status}`);
  }

  return response.text();
}
```

## AI Coding Instructions

- Keep EWS package references in `Pams.Email.csproj` aligned with the APIs used by the email component.
- Configure Exchange endpoint and authentication values through application configuration or environment variables; do not embed credentials in source code.
- Handle SOAP faults and non-success HTTP responses before processing Exchange mailbox data.
- Treat this as a legacy-format dependency and avoid changing package versions without validating Exchange compatibility.

## Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Injected or called by (1)

- `Pams.Email` — `Pams/Logic/Pams.Email/Pams.Email.csproj`:1
