Set up an SMTP Mailer on Cloudways (Gmail API)

Configure reliable WordPress email on Cloudways using WP Mail SMTP + the Gmail API—ideal for staging URLs that don’t have verified sending domains.

Posted by Philip Rudy on 04/04/2025 at 7:06am EST
WordPress Development WordPress Plugins

Table of Contents

Why use the Gmail API on Cloudways?

Most SMTP providers (SendGrid, Mailgun, Elastic Email) require DNS verification on a real domain. Cloudways staging URLs (e.g., https://wordpress-123456-9999999.cloudwaysapps.com) aren’t your production domain, so verification is awkward or impossible. The Gmail API authenticates via OAuth—no DNS records needed—making it perfect for staging or low-volume transactional email.

Good to know: The “From” address with the Gmail API should match the Google/Workspace mailbox you connect. WP Mail SMTP can optionally “force” the From address, but for best deliverability, keep it consistent.

Prerequisites

  • WordPress running on Cloudways (staging or production).
  • Ability to install plugins.
  • Access to a Google or Google Workspace account that will send mail.
  • Tip: Use one browser session from start to finish—Google will redirect back during OAuth.

Part 1 — Install & start WP Mail SMTP

  • Install and activate WP Mail SMTP (by WPForms).
  • Go to WP Mail SMTP → Settings and run the Setup Wizard.
  • Choose the Google / Gmail mailer. Leave the screen open when it asks for Client ID/Secret.

Part 2 — Create Gmail API credentials

  1. Enable the Gmail API
    • Open the Google Cloud Console.
    • Go to APIs & Services → Library → search “Gmail API” → click Enable.
  2. Configure OAuth consent
    • APIs & Services → OAuth consent screen.
    • Choose External, provide an app name and support email (generic is fine for staging).
  3. Create OAuth Client ID
    • CredentialsCreate credentialsOAuth client ID → type: Web application.
    • Authorized JavaScript origins — your Cloudways app URL, e.g.:
      Origin
      https://wordpress-563276-2954319.cloudwaysapps.com
    • Authorized redirect URIs — WP Mail SMTP connect URL:
      Redirect
      https://connect.wpmailsmtp.com/google/
  4. Production status
    • On the OAuth consent screen, set the app to In production.
    • If you skip this, authorization may fail or be limited.
  5. Get your Client ID & Secret
    • Credentials → under OAuth 2.0 Client IDs, click your app name.
    • Copy the Client ID and Client Secret into WP Mail SMTP.

Connect WP Mail SMTP to Google

  1. Return to the WP Mail SMTP wizard tab and paste your Client ID and Client Secret.
  2. Click Allow plugin to send emails using your Google account to start OAuth.
  3. Approve the consent prompts in Google → you’ll be redirected back to WordPress.
  4. Save settings.
Heads up: If you later map a custom domain to your Cloudways app (changing the site URL), add the new origin to your Google OAuth client. Mismatched origins cause redirect errors.

Send a test email

  • Go to WP Mail SMTP → Tools → Email Test.
  • Send a test to a mailbox you can check. Confirm delivery and “From” address.
  • If it fails, see Common issues below.

Notes for staging vs. production

  • Staging: Use a dedicated Google mailbox (e.g., staging-notify@yourdomain.com if you’re on Google Workspace) to keep logs and rate-limits separate.
  • Production: For higher volume or domain-branded mail, consider a provider with domain authentication (SPF, DKIM, DMARC). Gmail API is great for low-volume transactional and staging.
  • From address: Keep it consistent with the connected Google account for best deliverability.
  • Cloudways cron: If you rely on scheduled emails, ensure WordPress cron runs (either real cron or visitors). Cloudways lets you add system cron jobs if needed.

Common issues & fixes

  • OAuth redirect mismatch: Ensure the exact site origin is in Google’s “Authorized JavaScript origins” and the redirect is https://connect.wpmailsmtp.com/google/.
  • Still using another mailer plugin: Deactivate other SMTP/mail plugins to avoid conflicts.
  • App not in production: Switch the OAuth app to In production on the consent screen.
  • Changed Cloudways domain: If you bind a new primary domain, add its origin in your OAuth client and re-authorize WP Mail SMTP.
  • Gmail send limits: Personal Gmail and Google Workspace have daily send limits. For newsletters or bulk notifications, use a dedicated email service with domain authentication.

Alternatives (when to use a traditional SMTP)

If you need higher throughput, shared inboxes, or fine-grained bounce/complaint handling, consider a traditional SMTP provider: SendGrid, Mailgun, Amazon SES, or an email host offered by your DNS provider. You’ll authenticate your root domain with SPF/DKIM (and configure DMARC) for consistent delivery at scale.