User tests: Successful: Unsuccessful:
Pull Request resolves #43403 .
This version is party based on #47669 but replaces all the provider specific things. Also fixed the not working parts. Special tanks go to @dawe78 for creating the base implementation.
Added the needed fields and endpoints for xoauth2 for smtp.
This implementation has no provider specific presets, instead I will add a detail manual to guide for the microsoft and google implementation.
TBA
For now this is a draft, if you know how xoauth2 works the PR is tested with microsoft implementation and is known to work, additional tests are needed.
Not possible to test since it's a new feature
Sending works
Please select:
No documentation changes for guide.joomla.org needed
[] Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
Joomla supports OAuth 2.0 authentication for SMTP connections.
Instead of storing the password of the SMTP account, Joomla authorizes access through the mail provider. The provider returns a long-lived refresh token, which Joomla can later use to request short-lived access tokens for SMTP authentication.
The basic flow is:
Joomla
↓
OAuth provider authorization page
↓
User signs in and grants access
↓
Provider redirects back to Joomla
↓
Joomla receives an authorization code
↓
Joomla exchanges the code for tokens
↓
Refresh token is stored
↓
Access tokens are created when SMTP authentication is required
The SMTP password is therefore not used for OAuth 2.0 authentication.
The setup consists of several steps.
Do not assume that a newly created or modified OAuth application is immediately usable. Provider-side configuration changes can take some time to become effective.
Open:
System
→ Global Configuration
→ Server
→ Mail
Select:
Mailer: SMTP
SMTP Authentication: OAuth 2.0
Joomla then displays the OAuth 2.0 configuration fields.
The configured From Email Address should match the mailbox used as the SMTP username.
Example:
From Email Address:
user@example.com
SMTP Username:
user@example.com
For the standard OAuth 2.0 SMTP setup, both values should refer to the same mailbox.
Using a different From address can require additional provider-side permissions such as Send As, aliases, or delegated mailbox permissions and may otherwise cause the provider to reject the message.
The SMTP username identifies the mailbox Joomla uses for SMTP authentication.
Usually this is the complete email address:
user@example.com
The account authorized during the OAuth flow should normally be the same account.
The Client ID identifies the OAuth application registered with the mail provider.
It is generated by the provider when the OAuth application or OAuth client is created.
Example:
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee
The Client ID is not a secret.
The Client Secret authenticates the Joomla OAuth application to the provider.
It is created by the provider together with, or after creating, the OAuth application.
Example:
OAuth2 Client Secret:
••••••••••••••••
The Client Secret must be kept private.
It should not be:
The scope tells the provider which permissions Joomla requests.
Scopes are provider-specific.
For SMTP authentication, the scope usually grants permission to access or send mail through the user's mailbox.
One or more scopes can be requested.
If multiple scopes are required, they are normally separated by spaces:
scope1 scope2 scope3
The exact scope value depends on the mail provider.
The Authorize URL is the provider endpoint where the user signs in and grants Joomla access.
Joomla redirects the administrator to this URL when OAuth authorization is started.
The provider then:
The exact URL depends on the provider.
The Token URL is the provider endpoint Joomla uses to exchange OAuth credentials.
It is used for two important operations.
First, after authorization:
authorization code
↓
token endpoint
↓
access token + refresh token
Later:
refresh token
↓
token endpoint
↓
new access token
The administrator normally never interacts with this endpoint directly.
OAuth providers require Joomla's callback URL to be registered with the OAuth application.
For Joomla, the callback URL is:
https://www.example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
Replace:
https://www.example.com
with the actual Joomla site URL.
The redirect URI configured at the provider must match the URI Joomla sends during authorization.
In particular, check:
For example:
https://example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
and:
https://www.example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
are different redirect URIs.
For a typical single-tenant Microsoft 365 setup, use:
SMTP Host:
smtp.office365.com
SMTP Port:
587
SMTP Security:
STARTTLS
SMTP Authentication:
OAuth 2.0
From Email Address:
user@example.com
SMTP Username:
user@example.com
OAuth2 Client ID:
<Application (client) ID>
OAuth2 Client Secret:
<Client Secret Value>
OAuth2 Scope:
https://outlook.office.com/SMTP.Send offline_access
OAuth2 Authorize URL:
https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize
OAuth2 Token URL:
https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token
Register this redirect URI in Microsoft Entra:
https://www.example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
Also make sure Authenticated SMTP is enabled for the mailbox.
After changing the application, permissions, or Exchange settings, allow up to approximately one hour for changes to propagate.
The Microsoft setup consists of:
Changes to application registrations, permissions, consent, or Exchange settings may not become effective immediately. In some environments, propagation can take up to approximately one hour.
Open the Microsoft Entra admin center.
Navigate to:
Identity
→ Applications
→ App registrations
→ New registration
Enter a name such as:
Joomla SMTP OAuth
For a Joomla installation used with one Microsoft 365 organization, a single-tenant registration is normally appropriate:
Accounts in this organizational directory only
After registration, note:
Application (client) ID
Directory (tenant) ID
Both values are available on the application's Overview page.
Open:
App registrations
→ Joomla SMTP OAuth
→ Authentication
Add a platform:
Web
Register the Joomla callback URL:
https://www.example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
Use the real Joomla site URL.
Joomla requires delegated SMTP access.
The SMTP permission is:
https://outlook.office.com/SMTP.Send
Joomla also requires a refresh token so that SMTP authentication continues to work without the administrator signing in again.
Therefore the Joomla scope should include:
offline_access
The final scope is:
https://outlook.office.com/SMTP.Send offline_access
Depending on the organization's Microsoft Entra policies, administrator consent may be required.
Navigate to:
App registrations
→ Joomla SMTP OAuth
→ Certificates & secrets
→ Client secrets
→ New client secret
Create a secret.
Microsoft displays values such as:
Secret ID
Value
Joomla requires the actual:
Value
Do not enter the Secret ID.
Store the secret immediately because Microsoft may only display the value once.
OAuth authorization alone is not sufficient if SMTP AUTH is disabled for the mailbox.
In the Microsoft 365 admin center, check the affected user.
Navigate approximately to:
Users
→ Active users
→ User
→ Mail
→ Manage email apps
Ensure:
Authenticated SMTP
is enabled.
Organization-wide Exchange Online policies or Microsoft security settings can also disable SMTP AUTH.
If the OAuth flow succeeds but SMTP still fails, this setting should be one of the first things to verify.
Changes to Exchange or mailbox settings can take some time to propagate.
Use:
SMTP Host:
smtp.office365.com
SMTP Port:
587
SMTP Security:
STARTTLS
SMTP Authentication:
OAuth 2.0
From Email Address:
user@example.com
SMTP Username:
user@example.com
The From Email Address and SMTP Username should normally be identical.
Using a different sender address can require additional Microsoft 365 permissions such as Send As.
Use the:
Application (client) ID
from the Entra application.
Use the Client Secret Value.
https://outlook.office.com/SMTP.Send offline_access
For a single-tenant application:
https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize
Replace TENANT_ID with the Directory (tenant) ID.
https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token
Use the same tenant ID.
Save the Joomla configuration.
Start OAuth authorization.
Joomla redirects the browser to Microsoft.
Sign in using the account configured as:
SMTP Username
Approve the requested permissions.
Microsoft redirects the browser back to Joomla.
Joomla then exchanges the authorization code for OAuth tokens and stores the refresh token.
Afterwards Joomla can obtain new access tokens without requiring an interactive login.
For Gmail or Google Workspace, use:
SMTP Host:
smtp.gmail.com
SMTP Port:
587
SMTP Security:
STARTTLS
SMTP Authentication:
OAuth 2.0
From Email Address:
user@example.com
SMTP Username:
user@example.com
OAuth2 Client ID:
<Google OAuth Client ID>
OAuth2 Client Secret:
<Google OAuth Client Secret>
OAuth2 Scope:
https://mail.google.com/
OAuth2 Authorize URL:
https://accounts.google.com/o/oauth2/v2/auth
OAuth2 Token URL:
https://oauth2.googleapis.com/token
Register this redirect URI for the Google OAuth client:
https://www.example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
The OAuth client must use the application type:
Web application
Depending on the audience, publishing status, test-user configuration, and requested scopes, the OAuth application may need to be published or otherwise made available to the SMTP user.
After changing the OAuth application configuration, allow up to approximately one hour for changes to propagate.
The Google setup consists of:
Changes to Google OAuth configuration, consent configuration, scopes, test-user configuration, or application publishing may not become effective immediately. In some cases, allow up to approximately one hour before treating a configuration as broken.
Open Google Cloud Console.
Create a new project or select an existing project intended for the Joomla installation.
The OAuth configuration and credentials belong to this project.
Open:
Google Auth Platform
Configure the application's:
Branding
Audience
Data Access
At minimum configure:
For a Google Workspace organization, an application intended only for users inside the organization can normally use an internal audience.
For external applications, configure the appropriate publishing status and test users.
For Gmail SMTP OAuth access, use:
https://mail.google.com/
This grants OAuth access required for Gmail SMTP authentication.
The scope is considered sensitive or restricted by Google, so additional Google verification requirements can apply to public applications.
For private organizational use, particularly with Google Workspace, the requirements can differ.
Open:
Google Auth Platform
→ Clients
Create a new OAuth client.
Choose:
Web application
Joomla is a server-side web application and requires a Web OAuth client.
Under the OAuth client, add the authorized redirect URI:
https://www.example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
Use the exact Joomla URL.
The complete callback URL must be registered.
Registering only:
https://www.example.com
is not sufficient.
Depending on the configured audience and Google account type, the application may need to be published or users may need to be explicitly added as test users.
Before troubleshooting Joomla, verify that the account used for SMTP is actually allowed to authorize the OAuth application.
After changing:
allow some time for the changes to propagate.
In some cases this can take up to approximately one hour.
Google provides:
Client ID
Client Secret
A Google Client ID normally looks similar to:
123456789012-example.apps.googleusercontent.com
Copy both values into Joomla.
Keep the Client Secret private.
Use:
SMTP Host:
smtp.gmail.com
SMTP Port:
587
SMTP Security:
STARTTLS
SMTP Authentication:
OAuth 2.0
From Email Address:
user@example.com
SMTP Username:
user@example.com
The From Email Address and SMTP Username should normally be identical.
Using a different sender address can require additional alias or delegation configuration in Google Workspace or Gmail.
Use the OAuth Client ID created in Google Cloud.
Use the secret created for the Google OAuth client.
https://mail.google.com/
https://accounts.google.com/o/oauth2/v2/auth
https://oauth2.googleapis.com/token
Save the Joomla configuration.
Start OAuth authorization.
Joomla redirects the administrator to Google.
Sign in using the Gmail or Google Workspace account configured as:
SMTP Username
Approve the requested Gmail permission.
Google redirects back to Joomla.
Joomla exchanges the authorization code for OAuth tokens and stores the refresh token.
The refresh token is then used to request new short-lived access tokens whenever SMTP authentication is required.
After the setup is complete, verify the following:
OAuth 2.0.| Status | New | ⇒ | Pending |
| Category | ⇒ | Administration com_config Language & Strings Layout Libraries JavaScript NPM Change |
| Labels |
Added:
Language Change
NPM Resource Changed
PR-6.2-dev
|
||
took me a while as the test instructions are a bit too brief but I got there in the end and successfully sent email throguh google.
Only problem I had which I have not resolved is that I got a 403 when trying to get the token. I disabled my admintools generated htaccess in order to get the token. But I dont know what it was in the htaccess that caused the 403
Go to the [Google Cloud Console](https://console.cloud.google.com/).
Create a new Google Cloud project. Give it something obvious such as:
Joomla Gmail OAuth Test
You don't need to create anything else in the project; the project is essentially the container for your OAuth credentials.
In the Google Cloud Console, go to:
Google Auth Platform → Branding
If Google asks you to configure Google Auth Platform, click Get Started.
Enter an application name such as:
Joomla Mail OAuth Test
and your support email address. Google documents this current flow under the Google Auth Platform configuration.
Go to Google Auth Platform → Audience.
Because you're using Google Workspace, you will probably want:
Internal
if the Joomla site will only authenticate accounts belonging to your Workspace organisation.
This is particularly useful for testing because internal applications don't have the same external-app verification requirements. Google confirms that restricted/sensitive scopes used only internally within a Workspace organisation don't require Google's additional verification.
Go to Google Auth Platform → Data Access.
Add this scope:
https://mail.google.com/
There is an important caveat here: Google's current guidance considers https://mail.google.com/ a restricted scope. For SMTP/IMAP, Google says it is the full-mail scope, but recommends more limited Gmail API scopes where possible. If Joomla is actually using SMTP with OAuth/XOAUTH2, however, this broad scope is the one your instructions are specifying.
Now go to:
Google Auth Platform → Clients
Click Create Client.
Choose:
Application type: Web application
Google specifically says that server-side applications should use a Web application client and that the OAuth redirect URI must be registered against that client.
Give the client a name, for example:
Joomla Mail
Under Authorized redirect URIs, add the callback URL from your Joomla instructions.
For example, if your Joomla site is:
https://example.com
enter:
https://example.com/administrator/index.php?option=com_config&task=mail.oauth2callback&format=raw
Don't alter this URL. In particular, the query string is part of the redirect URI.
Google requires the redirect URI used by Joomla to exactly match one of the authorized redirect URIs configured for the OAuth client. Otherwise you'll get the dreaded:
redirect_uri_mismatch
error. Google also notes that changes to OAuth client settings can take from several minutes to a few hours to propagate.
Click Create.
Google will give you two important values:
Client ID
Client secret
Google warns that the client secret is only displayed after creation, so save it securely.
Configure mail in Joomla configuration
So your Joomla mail configuration would typically be:
SMTP Host: smtp.gmail.com
SMTP Port: 587
Encryption: TLS / STARTTLS
Authentication: XOAUTH2
Username: brian@example.com
Password:
OAuth Client ID: [Google Client ID]
OAuth Client Secret: [Google Client Secret]
Google Workspace Setup etc
...
13. Send a test mail
I added a documentation in the pr now, which should be used later on guide.joomla.org
@HLeithner after the recent changes do i need to retest this against google? Sorry I dont have any ms accounts to test with
@HLeithner after the recent changes do i need to retest this against google? Sorry I dont have any ms accounts to test with
would be great but I think the changes are minor enough if you don't have time now.
I have tested this item ✅ successfully on d8b1db5
I have tested this item ✅ successfully on d8b1db5
I tested succesfully using microsoft 365 client of mine.
I tested succesfully using microsoft 365 client of mine.
@HLeithner after the recent changes do i need to retest this against google? Sorry I dont have any ms accounts to test with
would be great but I think the changes are minor enough if you don't have time now.
still works
I have tested this item ✅ successfully on d8b1db5
Tested with my community.joomla.org account
I have tested this item ✅ successfully on d8b1db5
Tested with my community.joomla.org account
RTC
RTC
| Status | Pending | ⇒ | Fixed in Code Base |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2026-09-01 11:42:43 |
| Closed_By | ⇒ | MacJoom |
Thank you very much!
thank you all.
I think we need better codestyle checker ;-) thanks @QuyTon