Repository navigation
Microsoft 365 OAuth for EGroupware Mail
This page explains how to connect Microsoft 365 (Exchange Online) mailboxes to EGroupware Mail with OAuth2, and what an Entra ID (Azure AD) or Exchange Online administrator has to allow for it to work.
- No app registration in your tenant is needed. EGroupware uses its own multi-tenant Microsoft app. You do not create a client ID, client secret or redirect URI.
- Each user signs in to Microsoft once in a popup window (MFA is supported). EGroupware then stores a refresh token and accesses the mailbox via IMAP and SMTP with XOAUTH2.
- Your tenant must allow consent to the EGroupware app, and the mailboxes must have IMAP and SMTP AUTH enabled.
| Item | Value |
|---|---|
| Sign-in | Interactive OAuth2 authorization code flow in a popup, with refresh token |
| Microsoft endpoint |
https://login.microsoftonline.com/common/v2.0 (multi-tenant) |
| Permissions (all delegated) |
https://outlook.office.com/IMAP.AccessAsUser.All, https://outlook.office.com/SMTP.Send, offline_access, openid, email
|
| IMAP server |
outlook.office365.com, port 993, SSL/TLS |
| SMTP server |
smtp.office365.com, port 587, STARTTLS |
| Redirect | via the EGroupware OAuth proxy https://proxy.egroupware.org/oauth back to your installation (/egroupware/api/oauth.php) |
| Stored in EGroupware | only the refresh token, encrypted like a password; access tokens are requested as needed |
EGroupware does not use application permissions (IMAP.AccessAsApp) or the client credentials flow, so the Microsoft procedure with New-ServicePrincipal and Add-MailboxPermission is not required.
OAuth is used for onmicrosoft.com, Outlook, Hotmail and Live addresses, and for custom domains whose mailboxes are hosted in Microsoft 365 (mail server outlook.office365.com / smtp.office365.com).
On the first sign-in, Microsoft asks for consent to the permissions listed above.
-
If users may consent to apps in your tenant, every user consents in the popup themselves.
-
If user consent is restricted (common in organisations), an administrator must grant consent for the whole tenant once. Open the following URL as a Global Administrator, Privileged Role Administrator or Cloud Application Administrator, replace
<tenant>with your tenant ID or primary domain, and accept:https://login.microsoftonline.com/<tenant>/adminconsent?client_id=eb5e2a98-70a2-471c-9e0a-a665ba1dfb0eAlternatively, after a first sign-in attempt, grant consent under Entra admin center > Enterprise applications > EGroupware > Permissions > Grant admin consent.
After consent, the app shows up in your tenant as an Enterprise application. It is registered in EGroupware's tenant, not in yours, so there are no secrets or certificates for you to manage.
Sign-in happens in a browser popup on the user's device. Conditional Access policies that block unknown apps or locations, or that require a compliant or hybrid-joined device, can block it. Exclude the EGroupware enterprise application or adjust the policy if users get an access error after signing in.
According to Microsoft, SMTP AUTH is disabled while Security Defaults are enabled. Receiving mail via IMAP works, but sending fails. To send mail through EGroupware, disable Security Defaults and protect the tenant with Conditional Access instead, or send via another SMTP server.
Run these commands in Exchange Online PowerShell (Connect-ExchangeOnline).
IMAP must be enabled for the mailbox:
Get-CASMailbox -Identity user@example.com | Format-List ImapEnabled
Set-CASMailbox -Identity user@example.com -ImapEnabled $trueSMTP AUTH must be enabled, either for the whole organisation:
Set-TransportConfig -SmtpClientAuthenticationDisabled $falseor only for the mailboxes that use EGroupware (the mailbox setting overrides the organisation setting):
Set-CASMailbox -Identity user@example.com -SmtpClientAuthenticationDisabled $falseIn the Microsoft 365 admin center, the per-mailbox setting is under Users > Active users > (user) > Mail > Manage email apps > Authenticated SMTP.
Changes can take some time to become effective.
- Add the account in EGroupware Mail (or as administrator in Admin > Mail accounts) with the Microsoft 365 e-mail address.
- Leave the password fields for IMAP and SMTP empty. An empty password means "use OAuth, if supported".
- A popup opens with the Microsoft sign-in. Sign in, complete MFA if required, and accept the consent screen.
- The popup closes automatically, the token is saved and the mail app refreshes.
If the message "Successful, but NO refresh-token received!" appears, sign-in worked but Microsoft did not return a refresh token. Check that consent includes offline_access and try again.
Sieve (server-side filters and vacation notices) is not available for Microsoft 365 accounts. Use the rules in Outlook on the web instead.
-
Outgoing HTTPS from the EGroupware server to
login.microsoftonline.commust be allowed. If you use an HTTP proxy, configure it in EGroupware setup. - The session cookie SameSite setting must not be
Strict, because the sign-in returns to EGroupware via a cross-site redirect. - Keep EGroupware up to date. The Microsoft app, its secret and fixes for Microsoft sign-in are delivered with EGroupware updates.
Recent EGroupware versions have the setup option Microsoft Tenant ID (below the IdP URL in the setup configuration). If you enter your tenant ID there, Microsoft sign-ins are only accepted for that tenant.
If OAuth worked before and has stopped, the cause is usually a change in the Microsoft 365 tenant or mailbox. Check in this order:
-
Reconnect the account in EGroupware. Open the mail account and go through the Microsoft sign-in in the popup again. If only the refresh token had become invalid (e.g. after a password reset or revoked sessions), this fixes it. If it fails, note the error message shown, especially any
AADSTS…code. -
Entra sign-in logs. In the Entra admin center go to Monitoring > Sign-in logs and filter by the application "EGroupware" or the application ID
eb5e2a98-70a2-471c-9e0a-a665ba1dfb0e. Failed sign-ins show the error code and the reason, e.g. a blocking Conditional Access policy or missing consent. This is usually the quickest way to find the cause. -
Enterprise application. Under Enterprise applications, check that the EGroupware app still exists, that Enabled for users to sign-in? is set to Yes, and that the granted permissions (consent) are still in place.
-
Mailbox protocols. Check IMAP and SMTP AUTH for the affected mailbox:
Get-CASMailbox -Identity user@example.com | Format-List ImapEnabled, SmtpClientAuthenticationDisabled Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
ImapEnabledmust beTrue.SmtpClientAuthenticationDisabledmust beFalseon the mailbox, or empty on the mailbox andFalsefor the organisation. -
Recent tenant changes. Check whether anything changed around the time the problem started: new or changed Conditional Access policies, Security Defaults enabled, a stricter user consent policy, password resets or revoked sessions for the user.
| Symptom | Likely cause | What to do |
|---|---|---|
| Consent screen says admin approval is required | User consent is restricted in the tenant | Grant admin consent (see above) |
| Error after successful Microsoft sign-in, on an older EGroupware version | The Microsoft app used by older EGroupware versions is no longer valid | Update EGroupware |
| Receiving works, sending fails | SMTP AUTH disabled for the tenant or mailbox, or Security Defaults enabled | Enable SMTP AUTH (see above) |
| Login to IMAP fails after sign-in | IMAP disabled for the mailbox | Set-CASMailbox -ImapEnabled $true |
| Access blocked after sign-in | Conditional Access policy | Adjust the policy or exclude the EGroupware app |
| User is asked to sign in to Microsoft again | Refresh token expired or revoked (e.g. after a password reset or token revocation) | Sign in again in the popup |
| Popup does not return to EGroupware | Outgoing HTTPS blocked, or SameSite cookie set to Strict
|
Check server requirements above |
| No redirect to the Microsoft sign-in, only for mailboxes of another tenant (incl. personal Outlook.com accounts) | The setup option Microsoft Tenant ID is set to a different tenant. It restricts Microsoft OAuth for mail to that tenant as well | Enter the correct tenant ID, or leave the option empty if users need mailboxes from other tenants |
| Language: |
- General information
- Distribution specific instructions
- Update recommendations and troubleshooting
- Tuning EGroupware for higher number of users
- Docker-compose installation: Linux, Windows, Mac, Synology, QNAP
- Configure IMAP push
- Customizing EGroupware 26
- Customize login page, logo, fonts, login box
- Custom translations
- Custom fields
- Custom etemplate
- IMAP Push Notifications for Dovecot 2.2+
- Using EGroupware Mail server with ActiveDirectory
CTI / Computer Telephone Integration
- Rocket.Chat
- Moodle
- Wordpress
- Piwigo-Gallery
- Open WebUI
- Microsoft 365 mail via OAuth (EGroupware as client)
Using SmallPART with a LMS (Moodle, OpenOLAT, ...)
Synchronisation between Untis / Webuntis and EGroupware
Development