Send email with Gmail using this driver plugin for OctoberCMS.
- A Gmail account. Google Workspace (G Suite) accounts are also supported, if your administrator has enabled access.
- Gmail API credentials (see below).
The plugin is configured in your October CMS backend settings. Change the mail method to Gmail in Mail configuration, save the settings and go to Gmail configuration to upload your API credentials. Obtain API credentials from the Google Cloud Console.
- Go to the Google Cloud Console and create a new project.
- Give your project a name, and click Create. Wait for your project to be created.
- Click the Create credentials dropdown and choose OAuth client ID
- You may be asked to configure the OAuth consent screen
- Set the Application name
- Add your domain to the Autorized domains list
- Configure any other option as you like. More info here.
- Select Web application as the Application type, and give it a name.
- Copy the Authorized Redirect URI from the backend Gmail configuration page.
- Add that URI as an Authorized redirect URI and click Create
- Look for your new credential in the OAuth 2.0 Client IDs table, and click the download button to download your credentials in JSON format.
- Click on Library in the sidebar and search for "Gmail". Click Enable to enable access to the Gmail API.
- Upload the file you downloaded to the backend Gmail configuration page and save the settings. Reload the page to show the Authorize button.
- Click the Authorize button to open the Google consent page. Continue to select the account you want to send email with and consent to sending email on your behalf.
- You may encounter a screen that says "This app isn't verified". This is referring to the OAuth consent screen that you created, and can be bypassed by clicking Advanced and then Go to <domain> (unsafe).
To make sure everything is working, try test sending a mail template to yourself.
In case you want to revoke access, click Reset to default on the Gmail configuration page. This will delete the credentials and access tokens. You may also want to remove app access on your Google account.
- The Gmail API will only send emails as the account which you granted access with, it is currently not possible to send email as another user.
- You can send email using another email address you own, using an alias. Learn more. Change the Sender name and Sender email in Mail configuration to match your alias.
This section is for advanced users.
Note: To avoid overwriting your custom configuration with plugin updates, copy the provided config.php to your October CMS's config directory: config/zaxbux/gmailmailerdriver/config.php.
To provide the OAuth credentials without uploading them through the backend UI, you can add them in the plugin's config.php file. This is useful if you want to provide credentials using an environment variable. By default, the contents of the GOOGLE_APPLICATION_CREDENTIALS_JSON environment variable will be used.
Example:
'credentials' => '{"web": {"client_id": "000000000000-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com", ... }}',To change the authentication scopes (permissions requested from the user), you can override the default scopes in the plugin's config.php file. Add scopes to the google.scopes array. For the plugin to function correctly, the gmail.send scope is required. Gmail Auth Scopes
Example:
'scopes' => [
\Google_Service_Gmail::GMAIL_SEND,
\Google_Service_Gmail::GMAIL_READONLY,
],- 1.0.13 - Added Gmail alias documentation, added ability to pass credentials via envrionment vars.
- 1.0.12 - Improve UI.
- 1.0.11 - Increased max sending size to 35MB (encoded message size).
- 1.0.10 - Added ability to change auth scopes used with the Google API client.
- 1.0.9 - Improved localization.
- 1.0.8 - Plugin requires elevated permissions to function on restore password page.
- 1.0.7 - Added settings permissions
- 1.0.6 - Added authorization status dashboard widget.
- 1.0.5 - Cleaned up Gmail API authorization flow.
- 1.0.4 - Fixed issue where backend authorization status showed expired when it was authorized.
- 1.0.3 - Fixed logic issues, app is removed from user account when settings are reset. Updated dependencies.
- 1.0.2 - Fixed errors that occur when invalid credentials are supplied.
- 1.0.1 - First version.
All done!
- @alxy - Increased max sending size to 35MB.