Skip to content
Nederlands

Email Settings

CSDesk uses Microsoft Graph API to send and receive emails through Microsoft 365. This page explains how to set up the OAuth connection with delegated permissions.

Access: Settings → Email → Mail connection
Route: /admin/mail
Permissions: Admin only

The Settings hub is accessible via the gear icon in the navigation rail.

The Settings hub is accessible via the gear icon in the navigation rail.

Before configuring CSDesk, you need:

  1. Microsoft 365 tenant with mailbox access
  2. App registration in Microsoft Entra ID (formerly Azure AD) with:
    • Delegated permissions:
      • Mail.ReadWrite
      • Mail.Send
      • offline_access
      • User.Read
    • Redirect URI: The redirect URI shown on the Email settings page in CSDesk
  3. Client Secret created for the app registration
  4. Mailbox address (e.g., support@your-domain.com)
  1. Sign in to Azure Portal
  2. Navigate to Microsoft Entra ID → App registrations
  3. Click New registration
  4. Enter:
    • Name: CSDesk (or your preferred name)
    • Supported account types: Single tenant (your organization only)
    • Redirect URI: Web, use the redirect URI shown on the Email settings page in CSDesk
  5. Click Register
  1. In your app registration, go to API permissions
  2. Click Add a permission → Microsoft Graph → Delegated permissions
  3. Add these permissions:
    • Mail.ReadWrite (list and read inbox mail, mark processed messages as read)
    • Mail.Send (send mail as signed-in user)
    • offline_access (refresh tokens)
    • User.Read (read user profile)
  4. Click Grant admin consent for [Your Organization] and confirm. Without admin consent, the mailbox account may get a consent prompt it cannot approve, or no refresh token is issued.

Important: These must be Delegated permissions, not Application permissions. CSDesk never uses an app-only (client-credentials) token: it calls /me endpoints as the mailbox account that signed in.

  1. In your app registration, go to Certificates & secrets
  2. Click New client secret
  3. Enter:
    • Description: CSDesk production
    • Expires: Choose expiration period (1 year, 2 years, or custom)
  4. Click Add
  5. Copy the secret value immediately (it won’t be shown again)

From the app registration Overview page, copy:

  • Application (client) ID (GUID)
  • Directory (tenant) ID (GUID)
  1. In CSDesk, go to Settings → Email → Mail connection (/admin/mail)
  2. Under App registration, enter:
    • Directory (tenant) ID: Your tenant ID
    • Application (client) ID: Your app registration client ID
    • Client secret: The secret value you copied
    • Support mailbox: Email address of the mailbox CSDesk reads and sends from (e.g., support@your-domain.com)
  3. Click Save settings

The client secret is stored encrypted in the database and is write-only: leaving the field blank on a later save keeps the stored secret.

The Entra setup checklist next to the form shows the exact redirect URI to register.

After saving settings:

  1. Click Connect mailbox (shown once all four fields are filled in)
  2. You’ll be redirected to Microsoft. Sign in as the support mailbox account itself (the address you saved), not as another admin who has access to it
  3. Accept the consent prompt if it appears
  4. You’ll be redirected back to CSDesk with the message “Mailbox connected as …”

The status panel now shows Connected. CSDesk reads mail via the /me Microsoft Graph endpoints.

CSDesk checks the mailbox every 2 minutes (mail:ingest scheduled task):

  1. Fetches up to 25 unread messages from the inbox via /me/mailFolders/inbox/messages, oldest first
  2. Adds each message to an existing ticket or creates a new ticket
  3. Marks processed messages as read

Processed messages remain in the inbox (no Processed folder).

Once the mailbox is connected, CSDesk sends and receives through it. When an agent sends a reply:

  1. CSDesk creates a draft in the mailbox (POST /me/messages) and adds any attachments
  2. It tries to set its own Message-ID on the draft (best effort; Exchange may keep its own)
  3. It sends the draft; the email is delivered from the mailbox address, with the same address as Reply-To
  4. Mail without threading data or attachments goes out directly via /me/sendMail

Customer replies are matched to the ticket by a hidden reference in the email body, by In-Reply-To/References against stored Message-IDs, and by the [CSD-…] ticket number in the subject.

  • Access tokens: Stored encrypted, refreshed automatically when less than 3 minutes of validity remain
  • Refresh tokens: Stored encrypted, used to get new access tokens

Tenant ID, client ID, client secret and tokens are stored in the database.

After connecting, click Test connection. It refreshes the token if needed and reads the inbox folder (/me/mailFolders/inbox). It does not test sending.

The same check runs automatically every 6 hours (mail:health). If it fails, the status panel shows Attention needed with the error, and admins are alerted.

If the test fails, check:

  • The client secret is correct and has not expired
  • You signed in as the support mailbox account, not another user
  • Delegated permissions are granted with admin consent
  • The mailbox has an Exchange Online license

To disconnect the mailbox:

  1. Go to Settings → Email → Mail connection
  2. Click Disconnect
  3. Confirm the prompt “Disconnect the mailbox? Email intake and sending will stop.”

This deletes the stored tokens in CSDesk. It does not revoke the consent in Microsoft Entra; remove the app’s consent there if you also want that. Email intake and sending through Graph stop immediately.

CSDesk uses the OAuth 2.0 authorization code flow as a confidential web app (client secret), with a random state value checked on the callback. PKCE is not used.

  • Client secrets: Encrypted at rest in database
  • Access tokens: Encrypted at rest
  • Refresh tokens: Encrypted at rest

Delegated permissions mean CSDesk accesses the mailbox as the signed-in user, not with elevated application permissions. This follows the principle of least privilege.

Error: Microsoft returns “redirect URI mismatch”

Solution:

  1. Verify the redirect URI in Entra exactly matches the one shown on the Email page
  2. Scheme, host, port and path must match: no trailing slash, no http/https mismatch
  3. The platform type must be Web

Error: Graph API returns 403 Forbidden

Solution:

  1. Verify all 4 delegated permissions are added: Mail.ReadWrite, Mail.Send, offline_access, User.Read
  2. Grant admin consent if not already done
  3. Click Reconnect to sign in again with the new permissions

Error: “Token refresh failed”

Solution:

  1. Disconnect and reconnect the mailbox
  2. Check the client secret hasn’t expired in Entra
  3. Verify the app registration still exists in Entra

Check:

  1. Test connection should pass
  2. Only unread inbox messages are ingested; mail that is already read is skipped

Check:

  1. Verify mailbox can send (check Microsoft 365 admin center for mailbox send restrictions)
  2. Ensure send permissions granted

Microsoft Graph throttles requests per app and mailbox, and Exchange Online has its own sending limits.

CSDesk does not retry throttled requests automatically. A failed request is logged; unread mail that was not processed stays unread and is picked up by the next mail:ingest run.

When your client secret approaches expiry:

  1. Create a new client secret in Entra (don’t delete the old one yet)
  2. Paste the new secret into Client secret in CSDesk
  3. Click Save settings
  4. Click Test connection to verify
  5. Delete the old secret from Entra

The mailbox remains connected during rotation (no need to disconnect).


Next: