This approach is particularly useful because most SMTP providers like SendGrid, Mailgun, and others require an authorized domain name, which makes staging URLs incompatible. Notably, Elastic Email on Cloudways also doesn't support default staging URLs, making the Gmail API a viable alternative for this setup.
Note: Make sure you're doing this in the same browser and Google account, as the plugin will redirect to your Google account and request permission during the process.
Part 1: Setup WP Mail SMTP Plugin
- Install the WP Mail SMTP plugin via WordPress.
- Launch the Setup Wizard and choose the Google / Gmail option.
- Continue to the credentials screen. Once there, leave the screen open and proceed to Part 2 to create your Gmail API credentials.
Part 2: Setting Up Gmail API Credentials
- Enable Gmail API:
- Go to the Google Cloud Console.
- Click on APIs & Services, then search for and enable the Gmail API.
- If already enabled, click Manage.
- Create Gmail API Credentials:
- Click the Create Credentials button at the top right.
- Choose User Data for the data type.
- Follow the steps to enter your App Name, support email, etc. These can be generic.
- When prompted for OAuth Client ID:
- Authorized JavaScript origins: e.g.,
https://wordpress-563276-2954319.cloudwaysapps.com
- Authorized redirect URIs:
https://connect.wpmailsmtp.com/google/
- Authorized JavaScript origins: e.g.,
- Push App to Production:
- Go to the OAuth Consent Screen.
- Select Make External and set the app to In Production.
- Failure to do this step may result in the plugin not authenticating properly.
- Get Credentials for WP Mail SMTP:
- From the left navigation, click Credentials.
- Under OAuth 2.0 Client IDs, click your project name.
- Here you'll find your Client ID and Client Secret for use in WP Mail SMTP.