承接 lekoala/silverstripe-mailgun 相关项目开发

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

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

lekoala/silverstripe-mailgun

Composer 安装命令:

composer require lekoala/silverstripe-mailgun

包简介

Mailgun integration for SilverStripe CMS

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage Build Status codecov.io

Latest Stable Version Latest Unstable Version Total Downloads License Monthly Downloads Daily Downloads

codecov.io

Setup

Define in your .env file the following variables

MAILGUN_API_KEY='YOUR_API_KEY_HERE'
MAILGUN_DOMAIN='example.com'

or by defining the api key in your config.yml

LeKoala\Mailgun\MailgunHelper:
    api_key: 'YOUR_API_KEY_HERE'
    domain: 'example.com'

This module uses the official client Also make sure to check the official documentation

You can also autoconfigure the module with the following environment variables

# Will log emails in the temp folders
MAILGUN_ENABLE_LOGGING=true
# Will disable sending (useful in development)
MAILGUN_SENDING_DISABLED=true

By defining the Api Key, the module will register a new transport that will be used to send all emails.

If you're using the Mailgun EU service you can change the API endpoint

# Will use https://api.eu.mailgun.net/v3
MAILGUN_ENDPOINT='https://api.eu.mailgun.net/v3'

Debug

Create a postbin http://bin.mailgun.net/ and set the following parameters

MAILGUN_ENDPOINT='http://bin.mailgun.net/XXX'
MAILGUN_DEBUG=true

Please note that the test suite does not work with postbin because it returns html response and do not mock api behaviour

Register the new mailer

If you define the MAILGUN_API_KEY variable, the mailer transport will be automatically registered.

Otherwise, you need to call the following line:

MailgunHelper::registerTransport();

Mailgun integration

This module create a new admin section that allows you to:

  • List all messages events and allow searching them
  • Have a settings tab to list and configure sending domains and webhook

NOTE : Make sure that you have a valid api key (not a subaccount key) to access features related to installation of the webhook through the CMS.

Setting tags or metadata

By using custom headers you can pass parameters to the api by following the same principle than the SMTP api.

The main way to pass parameters is to add a json encoded string through the X-Mailgun-Variables header, but you can also use that Mandrill compatiblity layer.

$email = new Email();
$email->setSubject($subject);
$email->setBody($body);
// Through Mandrill compat layer
$email->getSwiftMessage()->getHeaders()->addTextHeader('X-MC-Metadata', json_encode(['FIRST_NAME' => 'Jon Smith']));
// Or use Mailgun
$email->getSwiftMessage()->getHeaders()->addTextHeader('X-Mailgun-Variables', json_encode(['FIRST_NAME' => 'Jon Smith']));

Webhooks

NOT IMPLEMENTED YET

From the Mailgun Admin, you can setup a webhook for your website. This webhook will be called and MailgunController will take care of handling all events for you. It is registered under the __mailgun/ route.

By default, MailgunController will do nothing. Feel free to add your own extensions to MailgunController to define your own rules, like "Send an email to the admin when a receive a spam complaint".

MailgunController provides the following extension point for all events:

  • onAnyEvent

And the following extensions points depending on the type of the event:

  • onEngagementEvent
  • onGenerationEvent
  • onMessageEvent
  • onUnsubscribeEvent

You can also inspect the whole payload and the batch id with

  • beforeProcessPayload : to check if a payload has been processed
  • afterProcessPayload : to mark the payload has been processed or log information

You can test if your extension is working properly by visiting /__mailgun/test if your site is in dev mode. It will load sample data from the API.

Please ensure that the url for the webhook is properly configured if required by using the following configuration

LeKoala\Mailgun\MailgunAdmin:
    webhook_base_url: 'https://my.domain.com/'

You can also define the following environment variable to log all incoming payload into a given directory. Make sure the directory exists. It is relative to your base folder.

MAILGUN_WEBHOOK_LOG_DIR='_incoming'

Preventing spam

  • Make sure you have properly configured your SPF and DKIM records for your domain.

    mydomain.com TXT "v=spf1 include:mailgun.org ~all"

  • Create a DMARC record

    _dmarc.mydomain.com. 3600 IN TXT "v=DMARC1; p=none; sp=none; rf=afrf; pct=100; ri=86400"

  • Leave provide_plain option to true or provide plain content for your emails

  • Use Mail Tester to troubleshoot your issues

Inlining styles

In order to have the best resulst, we use the package pelago\emogrifier to inline styles

If you want to restore default functionnality, use this

LeKoala\Mailgun\MailgunHelper:
    inline_styles: false

Todo

  • Support multiple domains

Compatibility

Tested with 4.4 but should work fine on any 4.x

Maintainer

LeKoala - thomas@lekoala.be

lekoala/silverstripe-mailgun 适用场景与选型建议

lekoala/silverstripe-mailgun 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.18k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 12.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 11
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-18