Symfony Mailer Transport for Gmail API including Google OAuth2 authentication.
- Symfony >= 5.4
Use Composer to install this bundle:
composer require sptec/gmail-api-mailer-bundle
// config/bundles.php
return [
// ...
Sptec\GmailApiMailerBundle\SptecGmailApiMailerBundle => ['all' => true],
];
If you don't use Symfony Flex you have create the following configuration
# config/packages/google_apiclient.yaml
services:
Google_Client:
class: Google_Client
calls:
- [setClientId, ['%env(GOOGLE_CLIENT_ID)%']]
- [setClientSecret, ['%env(GOOGLE_CLIENT_SECRET)%']]
###> google/apiclient ###
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
###< google/apiclient ###
###> symfony/mailer ###
MAILER_DSN=gmail+api://null
###< symfony/mailer ###
bin/console sptec:google:auth
Your Google access token will be stored as json environment variable GOOGLE_ACCESS_TOKEN
by using Symfony's secrets management system.
- Open the Google Cloud console.
- At the top-left, click Menu menu > APIs & Services > Credentials.
- Click Create Credentials > OAuth client ID.
- Click Application type > Web application.
- Enter a name for the OAuth client ID. (e.g. Symfony Gmail API Mailer)
- Add authorized redirect URIs. (default: http://localhost)
- Click Create.