Lean SMTP

Lean SMTP  /  Transports  /  Gmail / Google Workspace (OAuth)

Setup guide · API transport

Connect Gmail with OAuth.

This is the second Gmail transport. Instead of a service account and a domain-wide grant, you authorize one mailbox in the browser — so no Super Admin is needed. It is the simplest path when you control a single Workspace sending account but can't (or don't want to) set up domain-wide delegation.

You are here · OAuth

OAuth (per-mailbox)

Owner of one mailbox clicks Connect. No Super Admin. Consent screen must be Internal.

This guide ↓
Alternative · Service account

Service account

A Super Admin authorizes domain-wide delegation once; sends as any mailbox in the domain.

Service-account guide →
Workspace domains only

Like the service-account transport, this is for Google Workspace mailboxes, not consumer @gmail.com. The reason is the consent screen: only an Internal consent screen (a Workspace org) skips Google app verification and issues a non-expiring refresh token. A consumer (External) app gets 7-day tokens and the full verification burden. For a personal Gmail account, use SMTP with an app password.

01 How it works

Lean SMTP uses the OAuth 2.0 authorization-code flow against an OAuth client you create in your own Google Cloud project. You click Connect in the plugin, approve access in the Google consent screen once, and Google hands back a refresh token that the plugin stores encrypted. On each send it trades that refresh token for a one-hour access token and posts the message to the Gmail API — the same send path as the service-account transport.

The connected mailbox is captured automatically from the sign-in (the openid email scopes), so you never type the sending address.

What you'll end up with

(1) the Gmail API enabled, (2) the OAuth consent screen set to Internal, (3) a Web-application OAuth client whose authorized redirect URI is the plugin's callback, and (4) a Client ID + secret pasted into Lean SMTP, then Connect.

02 Before you start

  • A Google Workspace account that can send mail — the mailbox you'll connect, e.g. noreply@example.com.
  • Access to a Google Cloud project owned by that Workspace organization. The "Internal" consent-screen option only appears for projects under a Workspace org. (You do not need to be a Super Admin — that's the whole point versus the service-account method.)
  • Lean SMTP 0.6.0 or newer installed and activated.

03 Create a project & enable the Gmail API

In the Google Cloud Console, create (or pick) a project that belongs to your Workspace organization. Then open the Gmail API page and click Enable.

The Gmail API product page in the Google Cloud Console, with an Enable button and service name gmail.googleapis.com.
Google Cloud Console → Gmail API → Enable. (Same step as the service-account method.)

04 Set the consent screen to Internal

Open Google Auth Platform → Audience. The User type must be Internal. If you've never configured the consent screen, you'll be prompted to create it first (give it an app name and a support email) — choose Internal as the audience.

The Google Auth Platform Audience page showing User type set to Internal, with a Make external button.
Audience → User type → Internal. This is what avoids the "unverified app" warning and keeps the refresh token non-expiring.
If it says External

An External consent screen will still let you connect, but Google shows an "unverified app" / "Access blocked" warning on every consent and, in Testing mode, expires the refresh token after 7 days — so mail silently stops a week later. Keep it Internal.

05 Get the redirect URI from Lean SMTP

You'll need the plugin's callback URL when creating the OAuth client. In WordPress, go to Settings → Lean SMTP, set the mailer to Gmail / Google Workspace (OAuth), and copy the read-only Redirect URI shown there. It looks like:

https://your-site.com/wp-admin/admin-post.php?action=lean_smtp_gmail_oauth_callback
Copy it exactly

Google matches the redirect URI character for character — scheme, host, path and query all count. A trailing slash or an http/https mismatch is the #1 cause of a redirect_uri_mismatch error. Paste the plugin's value; don't retype it.

06 Create the OAuth client (Web application)

  1. Open Google Auth Platform → Clients and click Create client.
  2. Set Application type to Web application.
  3. Give it a name, e.g. lean-smtp.
  4. Under Authorized redirect URIs, click Add URI and paste the Redirect URI from Step 5.
  5. Click Create.
The Create OAuth client ID form with Application type set to Web application and the plugin's callback URL entered under Authorized redirect URIs.
Application type = Web application; add the plugin's Redirect URI under "Authorized redirect URIs".

07 Copy the Client ID and secret

Google shows the new client's Client ID and Client secret once. Copy both now (the secret isn't shown again — though you can always add a new secret later).

The 'OAuth client created' dialog showing the Client ID and Client secret with copy buttons and a warning that the secret won't be shown again.
Copy the Client ID and Client secret. (The secret shown here was created only for this screenshot and has been deleted.)

08 Connect in Lean SMTP

  1. Back in Settings → Lean SMTP with the mailer set to Gmail / Google Workspace (OAuth), paste the Client ID and Client Secret.
  2. Click Save Changes. A Connect a Google account button appears in the Connection row.
  3. Click Connect a Google account. You're sent to Google — sign in as the mailbox you want to send from and approve the request.
  4. You're returned to the settings page showing Connected as you@example.com. That address is captured from the sign-in automatically.
  5. In the From section, set From Email to the connected address (or an alias it may send as), and enable Force From if other plugins set their own.
The Lean SMTP settings OAuth section: the read-only Redirect URI, Client ID and Client Secret fields, and the Connection row showing 'Connected as' with a Disconnect button.
The Gmail OAuth section in Lean SMTP — Redirect URI (read-only), Client ID and Secret, and the Connection row (shown here after a successful connect, with Disconnect). Before connecting, this row shows a "Connect a Google account" button.

09 Configure in wp-config.php (optional)

The client ID and secret can be pinned as constants, which beat the stored options and lock the fields in the admin. The refresh token and connected mailbox come from the Connect flow, so they're not set this way:

wp-config.php
define( 'LEAN_SMTP_MAILER', 'gmail_oauth' );
define( 'LEAN_SMTP_FROM_EMAIL', 'noreply@example.com' );
define( 'LEAN_SMTP_GMAIL_OAUTH_CLIENT_ID', '1234567890-abc.apps.googleusercontent.com' );
define( 'LEAN_SMTP_GMAIL_OAUTH_CLIENT_SECRET', getenv( 'LEAN_SMTP_GMAIL_OAUTH_SECRET' ) );
Still click Connect

Even with the ID and secret in constants, you must do the browser Connect once to grant the mailbox and store the refresh token. Pin the ID/secret, then Connect.

10 Send a test email

  • Use the Send a Test Email button on the settings page, or
  • Run WP-CLI:
wp lean-smtp test
$ wp lean-smtp test you@example.com

Success: Test email sent to you@example.com.

wp lean-smtp status shows the mailer, the client ID and whether an account is connected — never the secret or refresh token.

11 Troubleshooting

SymptomLikely cause & fix
redirect_uri_mismatch The redirect URI on the OAuth client doesn't match the plugin's exactly. Copy the read-only Redirect URI from Lean SMTP and paste it into the client's Authorized redirect URIs — mind the scheme and trailing slash.
Access blocked / unverified The consent screen is External, not Internal. Switch it to Internal (Step 4). External needs Google verification for the gmail.send restricted scope.
No refresh token returned Google reused a prior grant. Remove the app under your Google Account → third-party access, then click Connect again. (The plugin forces prompt=consent to avoid this.)
"Reconnect the account" The stored authorization was revoked or expired (invalid_grant). The plugin drops it and shows Connect again — just reconnect.
Didn't return the address The consent didn't include the email scope. The plugin requests openid email automatically; if you edited scopes, restore them and reconnect.
From rejected The From Email isn't the connected mailbox or a permitted alias. Align them, or enable Force From.

12 Which method should I use?

OAuth (this guide)Service account
Who approvesThe mailbox owner, in the browserA Workspace Super Admin
Scope of accessOne connected mailboxAny mailbox in the domain
SetupOAuth client + one-time ConnectService-account key + domain-wide delegation
Best whenYou run a single sending account and can't get a domain-wide grantYou're the admin and want it set once for the whole domain

Both use the same Gmail API and the same send path. See the service-account guide for that method.

13 Security notes

  • Least privilege. The grant is scoped to gmail.send (plus openid email to read the address) — send only, no inbox access.
  • Encrypted at rest. The client secret and refresh token are AES-256 encrypted against your site salts and never re-displayed.
  • Revoking is one click. Disconnect in Lean SMTP revokes the grant at Google and forgets it locally. You can also remove it from the account's third-party access.
  • Rotate the secret in the Google Cloud client if it may have leaked, update it in the plugin, and reconnect.
Still stuck?

Open an issue on GitHub or ask on the WordPress.org support forum. Google's reference for this flow is OAuth 2.0 for web server apps.