lukesnowden/laravel-mailjet

用于处理Mailjet API V3和Laravel Mailjet邮件传输的Laravel包

2.1.0 2020-01-21 08:12 UTC

README

Build Status Packagist Packagist GitHub license Documentation

使用此包装器处理Mailjet API v3的Laravel包:[https://github.com/mailjet/mailjet-apiv3-php](https://github.com/mailjet/mailjet-apiv3-php)

它还提供了Laravel邮件功能的mailjetTransport

安装

首先,将包包含在您的依赖项中

composer require mailjet/laravel-mailjet

然后,您需要在配置文件中添加一些信息。您可以在这里找到您的Mailjet API密钥/密钥

  • 在提供者数组中
'providers' => [
    ...
    Mailjet\LaravelMailjet\MailjetServiceProvider::class,
    Mailjet\LaravelMailjet\MailjetMailServiceProvider::class,
    ...
]
  • 在别名数组中
'aliases' => [
    ...
    'Mailjet' => Mailjet\LaravelMailjet\Facades\Mailjet::class,
    ...
]
  • 在services.php文件中
mailjet' => [
    'key' => env('MAILJET_APIKEY'),
    'secret' => env('MAILJET_APISECRET'),
]
  • 在您的.env文件中
MAILJET_APIKEY=YOUR_APIKEY
MAILJET_APISECRET=YOUR_APISECRET

完整配置

'mailjet' => [
    'key' => env('MAILJET_APIKEY'),
    'secret' => env('MAILJET_APISECRET'),
    'transactional' => [
        'call' => true,
        'options' => [
            'url' => 'api.mailjet.com',
            'version' => 'v3.1',
            'call' => true,
            'secured' => true
        ]
    ],
    'common' => [
        'call' => true,
        'options' => [
            'url' => 'api.mailjet.com',
            'version' => 'v3',
            'call' => true,
            'secured' => true
        ]
    ]
]

您可以将设置传递给MailjetClient

  • transactional:发送API客户端的设置
  • common:设置通过Mailjet Facade访问的MailjetClient

邮件驱动配置

为了使用Mailjet作为您的邮件驱动,您需要更新config/mail.php或您的.env文件中的邮件驱动,并将其设置为MAIL_DRIVER=mailjet,并确保您使用的是在您的Mailjet账户上配置的有效和授权的发送电子邮件地址。发送电子邮件地址和域名可以在这里管理

有关用法,请参阅Laravel邮件文档

用法

为了使用此包,您首先需要在您的代码中导入Mailjet Facade

use Mailjet\LaravelMailjet\Facades\Mailjet;

然后,在您的代码中,您可以使用MailjetServices中可用的方法之一

低级API方法

  • Mailjet::get($resource, $args, $options)
  • Mailjet::post($resource, $args, $options)
  • Mailjet::put($resource, $args, $options)
  • Mailjet::delete($resource, $args, $options)

高级API方法

  • Mailjet::getAllLists($filters)
  • Mailjet::createList($body)
  • Mailjet::getListRecipients($filters)
  • Mailjet::getSingleContact($id)
  • Mailjet::createContact($body)
  • Mailjet::createListRecipient($body)
  • Mailjet::editListrecipient($id, $body)

有关您可以在每个方法中使用的过滤器的更多信息,请参阅Mailjet API文档

所有方法返回Mailjet\Response或抛出MailjetException(如果API发生错误)。

您还可以使用方法getClient()获取Mailjet API客户端,并自己向Mailjet API发出自定义请求。

待办事项

  • 添加额外的单元测试以增加代码覆盖率。