承接 mailjet/mailjet-swiftmailer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mailjet/mailjet-swiftmailer

Composer 安装命令:

composer require mailjet/mailjet-swiftmailer

包简介

A SwiftMailer transport implementation for Mailjet

README 文档

README

Build Status Packagist Packagist GitHub license

A SwiftMailer transport implementation for Mailjet ([NEW] we now support send API v3.1 ) Mailjet Send API v3.1 Compatible Mailjet send API V3 and V3.1

If you found any problem, feel free to open an issue!

TODO

  • Adding URL tags
  • Sandbox Mode
  • Improve unit-tests (lots of code duplications)

Installation

Require the package with composer

composer require mailjet/mailjet-swiftmailer

Usage Example

$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret);
$transport->setClientOptions(['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => true]);


$transport->send($message);

(Send API v3 is selected by default)

Mailjet client custom configuration

You can pass an array in transport's constructor or use setClientOptions function:

$clientOptions = ['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => false];
$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret, $clientOptions);


or

$transport->setClientOptions(['url' => "api.mailjet.com", 'version' => 'v3.1', 'call' => true]);

Properties of $options:

  • url (Default: api.mailjet.com) : domain name of the API
  • version (Default: v3) : API version (only working for Mailjet API V3 +)
  • call (Default: true) : turns on(true) / off the call to the API
  • secured (Default: true) : turns on(true) / off the use of 'https'

Mailjet custom headers

It is possible to set specific Mailjet headers or custom user-defined headers, through SwiftMailer.

For example:

$headers = $message->getHeaders();

$headers->addTextHeader('X-MJ-TemplateID', $templateId);
$headers->addTextHeader('X-MJ-TemplateLanguage', true);
$vars = array("myFirstVar" => "foo", "mySecondVar" => "bar");
$headers->addTextHeader('X-MJ-Vars', json_encode($vars));

Note: You need to json_encodeyour array of variables in order to be compatible with SMTP transport.

Mailjet bulk sending

$emails = ['f001@bar.com', 'f002@bar.com', 'f003@bar.com', 'f004@bar.com', 'f005@bar.com', 'f006@bar.com', ...]

$messages = [];
foreach ($emails as $email) {
    $message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
    $message
        ->addTo($email)
        ->addFrom('from@example.com', 'From Name')
        ->addReplyTo('reply-to@example.com', 'Reply To Name')
    ;

    array_push($messages, $message);
}
$transport = new MailjetTransport($dispatchEvent, $apiKey, $apiSecret);
$result = $transport->bulkSend($messages);

Note: does not work with Spool (SwiftMailer removed bulkSend from its API).

Integration in Symfony

If you want to use MailjetTransport in your Symfony project follow these small steps:

  1. composer require mailjet/mailjet-swiftmailer
  2. Into your services.yml, register MailjetTransport:
swiftmailer.mailer.transport.mailjet:
    class: Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport
    arguments:
        - "@swiftmailer.transport.eventdispatcher.mailjet"
        - "%mailjet.api_key%"
        - "%mailjet.secret_key%"

Note: We set mailjet.api_key and mailjet.secret_key into parameters.yml

  1. Finally, configure SwiftMailer in your config.yml:
# Swiftmailer Configuration
swiftmailer:
    transport: mailjet

Note: You can also inject your own Mailjet\Client:

mailjet.transactionnal.client:
    class: "%mailjet.client.class%"
    arguments:
        - "%mailjet.api_key%"
        - "%mailjet.secret_key%"
        - %mailjet.transactionnal.call%
        - %mailjet.transactionnal.options%

swiftmailer.transport.eventdispatcher.mailjet:
    class: Swift_Events_SimpleEventDispatcher

swiftmailer.mailer.transport.mailjet:
    class: Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport
    arguments:
        - "@swiftmailer.transport.eventdispatcher.mailjet"
        - "%mailjet.api_key%"
        - "%mailjet.secret_key%"
        - %mailjet.transactionnal.call%
        - %mailjet.transactionnal.options%
    calls:
        - method: setExternalMailjetClient
          arguments:
              - '@mailjet.transactionnal.client'

Mailjet references

Execute Tests

vendor/bin/phpunit -c .

Contributing

If you want to contribute to this project, look at over here

mailjet/mailjet-swiftmailer 适用场景与选型建议

mailjet/mailjet-swiftmailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.26M 次下载、GitHub Stars 达 25, 最近一次更新时间为 2017 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「swiftmailer」 「Mailjet」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mailjet/mailjet-swiftmailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mailjet/mailjet-swiftmailer 我们能提供哪些服务?
定制开发 / 二次开发

基于 mailjet/mailjet-swiftmailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.26M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 22
  • 依赖项目数: 16
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 9
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-16