# Mautic OAuth 2.0 Plugin to Send Email Messages

**URL:** <https://forum.mautic.org/t/mautic-oauth-2-0-plugin-to-send-email-messages/29025>\
**Category:** Mautic 3 - Install/Upgrade Support\
**Tags:** discussion\
**Created:** [August 22, 2023, 3:53pm UTC](https://forum.mautic.org/t/mautic-oauth-2-0-plugin-to-send-email-messages/29025 "2023-08-22T15:53:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![team](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@team](https://forum.mautic.org/u/team)\
**Post date:** [August 22, 2023, 3:53pm UTC](https://forum.mautic.org/t/mautic-oauth-2-0-plugin-to-send-email-messages/29025/1 "2023-08-22T15:53:39Z")

</div>

**EasyApache 4**  
**My Mautic version is: 45\_mautic-449**  
**My PHP 80, PHP 8.0.29-1.1.3.cpanel**  
**extention: php80-php-fileinfo**  
**cPanel & WHM on AlmaLinux**  
**OS: AlmaLinux v8.8.0 STANDARD kvm**  
**cPanel Version 112.0.5**

Hi everyone,

I have a request for help finding a Mautic plugin built to send outbound email messages from my Mautic client to Gmail API server:

The plugin description reads as follows: The plugin configures OAuth 2.0 client with Mautic for secure authentication when sending email messages. The steps involve enabling the OAuth 2 Two-Legged Authentication plugin, entering the OAuth client details, including the client ID and secret, and configuring the authorization and access token URLs. After saving the settings, you can assign the OAuth 2.0 client to specific email services and proceed to create email campaigns using OAuth 2.0 authentication.

How to configure Gmail API settings for sending outbound email messages from a Mautic client to a Firebase Gmail API server:  
Here are the step-by-step instructions to set up the Firebase project and enable the Gmail API:

Guide to Configure OAuth 2.0 Client with Mautic

Step 1: Log in to your Mautic account and access the admin dashboard.

Step 2: Navigate to the “Configuration” section in the top menu.

Step 3: From the dropdown menu, select “Plugins.”

Step 4: Search for “OAuth” and click on “OAuth 2 Two-Legged Authentication” to enable it.

Step 5: After enabling the plugin, click on the gear icon (settings) next to the “OAuth 2 Two-Legged Authentication” plugin.

Step 6: Fill in the following details:

Enabled: Check the box to enable the OAuth 2 Two-Legged Authentication plugin.  
Client Key: Enter the OAuth client ID obtained when creating your OAuth client.  
Client Secret: Enter the client secret associated with the OAuth client.  
Authorize URL: Enter the authorization URL specific to the OAuth provider (e.g., Gmail API).  
Access Token URL: Enter the access token URL specific to the OAuth provider.  
Redirect URI: Enter the URL where users will be redirected after granting access.  
Step 7: Click the “Apply” button to save the changes.

Step 8: Configure OAuth settings for each email service. Go to the “Email Settings” in the Mautic dashboard.

Step 9: For each email service, select the OAuth 2.0 client you created from the dropdown list.

Step 10: Save the changes.

Step 11: Proceed to create email campaigns and use the OAuth 2.0 credentials to send emails through the selected email service.

Summary:  
The guide provides a step-by-step process to configure OAuth 2.0 client with Mautic for secure authentication when sending email messages. The steps involve enabling the OAuth 2 Two-Legged Authentication plugin, entering the OAuth client details, including the client ID and secret, and configuring the authorization and access token URLs. After saving the settings, you can assign the OAuth 2.0 client to specific email services and proceed to create email campaigns using OAuth 2.0 authentication.

Thanks,  
Hal

---

<div class="post-metadata">

**Author:** ![joeyk](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/joeyk/32/11164_2.png) [@joeyk](https://forum.mautic.org/u/joeyk)\
**Post date:** [August 23, 2023, 10:15am UTC](https://forum.mautic.org/t/mautic-oauth-2-0-plugin-to-send-email-messages/29025/2 "2023-08-23T10:15:32Z")

</div>

Plz note, that soon Mautic 5 stable will come out and you’ll have to use Symfony Mailer to do so.

---

<div class="post-metadata">

**Author:** ![team](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@team](https://forum.mautic.org/u/team)\
**Post date:** [August 28, 2023, 12:56pm UTC](https://forum.mautic.org/t/mautic-oauth-2-0-plugin-to-send-email-messages/29025/3 "2023-08-28T12:56:34Z")

</div>

joeyk,

Does Mautic 5 stable resolve the following error message, /home/mautic/public\_html/mautic.devced.com/var/logs/mautic\_prod-2023-08-28.php:

> [2023-08-28 05:50:35] mautic.ERROR: [MAIL ERROR] Connection could not be established with host [smtp.gmail.com](http://smtp.gmail.com) :stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3\_get\_record:wrong version number Log data: ++ Starting Swift\_Transport\_EsmtpTransport !! Connection could not be established with host [smtp.gmail.com](http://smtp.gmail.com) :stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1408F10B:SSL routines:ssl3\_get\_record:wrong version number (code: 0) (send); [director@CforED.com](mailto:director@CforED.com) {“exception”:“[object] (Swift\_TransportException(code: 0): Connection could not be established with host [smtp.gmail.com](http://smtp.gmail.com) :stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1408F10B:SSL routines:ssl3\_get\_record:wrong version number\nLog data:\n++ Starting Swift\_Transport\_EsmtpTransport\n!! Connection could not be established with host [smtp.gmail.com](http://smtp.gmail.com) :stream\_socket\_client(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1408F10B:SSL routines:ssl3\_get\_record:wrong version number (code: 0) at /home/mautic/public\_html/mautic.devced.com/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Plugins/LoggerPlugin.php:124)”} {“hostname”:“[35-236-118-198.cprapid.com](http://35-236-118-198.cprapid.com)”,“pid”:521049}

See the captured screenshot image:

 ![2023-08-28 05.21.01 mautic.devced.com 65a74ba7c89f](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/7/7469aadb799179a29a22aad862b44bd07d8ac4bc.png)

Regards,  
Hal

---

<div class="post-metadata">

**Author:** ![amanank](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/amanank/32/13561_2.png) [@amanank](https://forum.mautic.org/u/amanank)\
**Post date:** [January 20, 2025, 9:11pm UTC](https://forum.mautic.org/t/mautic-oauth-2-0-plugin-to-send-email-messages/29025/5 "2025-01-20T21:11:31Z")

</div>

I faced similar issues and decided to create a fix myself. Here’s what I did:

After changing the email DSN to:

```conf
gmail://${G_OAUTH2_SMTP_USER}@default?client_id=${G_OAUTH2_CLIENT_ID}&client_secret=${G_OAUTH2_CLIENT_SECRET}&refresh_token=${G_OAUTH2_REFRESH_TOKEN}

```

I encountered the error: “gmail protocol not supported; install `symfony/google-mailer`.”

Even after installing it, I kept getting authentication errors. The issue is that `google-mailer` does not exchange the refresh token for an access token to use as a password.

Since `google-mailer` uses a static class, it can’t be extended:

```php
final class GmailTransportFactory extends AbstractTransportFactory

```

The class that instantiates Gmail transport is also static and has hard-coded factory classes, so extending it wasn’t an option either:

```php
final class Transport
{
    private const FACTORY_CLASSES = [
        BrevoTransportFactory::class,
        GmailTransportFactory::class,
        InfobipTransportFactory::class,
        MailerSendTransportFactory::class,
        MailgunTransportFactory::class,
        MailjetTransportFactory::class,
        MailPaceTransportFactory::class,
        MandrillTransportFactory::class,
        OhMySmtpTransportFactory::class,
        PostmarkTransportFactory::class,
        ScalewayTransportFactory::class,
        SendgridTransportFactory::class,
        SendinblueTransportFactory::class,
        SesTransportFactory::class,
    ];
}

```

I ended up patching it by adding the following function to `vendor/symfony/google-mailer/Transport/GmailTransportFactory.php`:

```php
protected function getPassword(Dsn $dsn): string
{
    $response = $this->client->request('POST', 'https://oauth2.googleapis.com/token', [
        'body' => [
            'client_id' => $dsn->getOption('client_id'),
            'client_secret' => $dsn->getOption('client_secret'),
            'refresh_token' => $dsn->getOption('refresh_token'),
            'grant_type' => 'refresh_token',
        ],
    ]);

    $data = $response->toArray();
    //dd($data);
    return $data['access_token'];
}

```

I also created a GitHub repository for Gmail OAuth2 support. You can check it out here: [GitHub Repository](https://github.com/amanank/docker-mautic-google-oauth2).
