urchihe / laravel-mailjet
带有包装器的mailjet包
dev-master
2020-06-02 16:41 UTC
Requires
- php: >=7
- mailjet/mailjet-apiv3-php: ^1.4
- mailjet/mailjet-swiftmailer: ^2.0
Requires (Dev)
- fzaninotto/faker: ^1.9.1
- laravel/framework: ^7.0|^8.0
- mockery/mockery: ^1.3.1
- nunomaduro/collision: ^4.1
- orchestra/testbench: ^5.3
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-29 05:29:10 UTC
README
Laravel包,用于通过此包装器处理Mailjet API v3: https://github.com/mailjet/mailjet-apiv3-php
它还提供Laravel邮件功能的mailjetTransport
安装
首先,将包包含在您的依赖项中
composer require urchihe/laravel-mailjet
然后,您需要在配置文件中添加一些信息。您可以在这里找到您的Mailjet API密钥/密钥
- 在services.php文件中
'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 ] ] ]
- 在您的.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_MAILER=mailjet
,MAIL_HOST=in-v3.mailjet.com
,MAIL_PORT=2525
,并将以下内容添加到config/mail
中的mailers
数组中
'mailjet' => [ 'transport' => 'mailjet', 'host' => env('MAIL_HOST'), 'port' => env('MAIL_PORT'), 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'timeout' => null, ],
.
有关用法,请参阅Laravel邮件文档
用法
为了使用此包,您首先需要在代码中导入Mailjet Facade
use Urchihe\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
,或者在API错误的情况下抛出MailjetException
。
您还可以使用getClient()
方法获取Mailjet API客户端,并自行向Mailjet API发送自定义请求。
待办事项
- 添加更多单元测试以增加代码覆盖率。