milind/laravel-gmail-mail-driver

此包用于为Laravel提供Gmail邮件驱动程序

0.2 2021-02-16 10:44 UTC

This package is auto-updated.

Last update: 2024-09-16 18:23:03 UTC


README

此包用于为Laravel中的邮件驱动程序提供Gmail电子邮件服务提供者。

这是一个简单的包装器,因此您需要自行管理认证和应用程序审批流程,并且还需要管理刷新访问令牌的流程。

config/mail.php 中添加新的 mailers 驱动程序,如下所示:

'gmail' =>[
    'transport' => 'gmail'
]

config/services.php 中添加新的 gmailmailer 服务,如下所示:

'gmailmailer' => [
    'AppName' => 'Your-app-name',
    'scopes' => [
        /* We need both the scopes for the API to send the email */
        Google_Service_Gmail::GMAIL_READONLY, // This scope is used to get the user's email address (From which we are sending emails)
        Google_Service_Gmail::GMAIL_SEND      // This scope is used to send the emails.
    ],
    'authConfig' => [
    /* 
    *  We are getting this details from the Google console.
    *
    */
        "web" => [
            "client_id" => env('GOOGLE_EMAIL_SEND_API_CLIENT_ID'),
            "client_secret" => env('GOOGLE_EMAIL_SEND_API_CLIENT_SECRET'),
            "redirect_uris" => [
                env('GOOGLE_EMAIL_SEND_API_REDIRECT')
            ],
        ]
    ],
    'tokenType' => 'offline',
    'prompt' => 'select_account consent',
]

您还需要将来自Google账户的访问令牌动态地/手动添加到gmailmailer中。

我个人更喜欢动态方式。

您需要将其作为数组添加。

Config::set('services.gmailmailer.accesstoken', $accessToken);

其中 $accessToken 将如下所示:

$accessToken = [
    "access_token" => "...",
    "expires_in" => ...,
    "refresh_token" => "...",
    "scope" => "...",
    "token_type" => "...",
    "created" => ...
];