sptec / 邮件API工具包
适用于Gmail API的Symfony Mailer传输,包括Google OAuth2身份验证。
dev-main
2022-10-23 16:44 UTC
Requires
- php: >=7.4
- google/apiclient: ^2.0
- symfony/config: ^5.4|^6.0
- symfony/dependency-injection: ^5.4|^6.0
- symfony/mailer: ^5.4|^6.0
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^9.5
- symfony/http-client: ^5.4|^6.0
- symfony/phpunit-bridge: ^5.4|^6.0
- symplify/easy-coding-standard: ^11.1
This package is auto-updated.
Last update: 2024-09-23 21:14:34 UTC
README
适用于Gmail API的Symfony Mailer传输,包括Google OAuth2身份验证。
需求
- Symfony >= 5.4
安装
步骤1:下载Bundle
使用Composer安装此Bundle
composer require sptec/gmail-api-mailer-bundle
步骤2:启用Bundle
// config/bundles.php return [ // ... Sptec\GmailApiMailerBundle\SptecGmailApiMailerBundle => ['all' => true], ];
配置
Google API客户端
如果您不使用Symfony Flex,则需要创建以下配置
# config/packages/google_apiclient.yaml services: Google_Client: class: Google_Client calls: - [setClientId, ['%env(GOOGLE_CLIENT_ID)%']] - [setClientSecret, ['%env(GOOGLE_CLIENT_SECRET)%']]
.env
###> google/apiclient ### GOOGLE_CLIENT_ID= GOOGLE_CLIENT_SECRET= ###< google/apiclient ### ###> symfony/mailer ### MAILER_DSN=gmail+api://null ###< symfony/mailer ###
用法
bin/console sptec:google:auth
您的Google访问令牌将使用Symfony的密钥管理系统存储为名为GOOGLE_ACCESS_TOKEN
的json环境变量。
Google凭证
- 打开Google Cloud控制台。
- 在左上角,点击菜单 > APIs & Services > 凭证。
- 点击创建凭证 > OAuth客户端ID。
- 点击应用程序类型 > 网络应用程序。
- 为OAuth客户端ID输入名称。(例如:Symfony Gmail API Mailer)
- 添加授权重定向URI。(默认:https://)
- 点击创建。