wowmarketingcz/laravel-mailjet

Laravel用于处理Mailjet API V3的包,支持Laravel Mailjet邮件传输

dev-master 2018-05-16 12:30 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:31:58 UTC


README

Build Status Packagist Packagist GitHub license Documentation

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

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

/!\ 安装Laravel 5.5 🛠️

在您的composer.json中

"mailjet/laravel-mailjet": "dev-laravel5.5",

安装

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

composer require WOWMarketingCZ/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访问的设置

邮件驱动程序配置

为了将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发出自定义请求。

待办事项

  • 添加更多单元测试以增加代码覆盖率。