承接 reelworx/t3-mailservice 相关项目开发

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

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

reelworx/t3-mailservice

Composer 安装命令:

composer require reelworx/t3-mailservice

包简介

A library for TYPO3 extensions to conveniently send emails using Fluid templates with HTML and TXT content

README 文档

README

This library can be used by TYPO3 extensions to have a convenient toolset to send email.

Features

  • Fluid-based mail templates for HTML and TEXT format
  • Multiple languages (including fallback)
  • Usable in all contexts (frontend, backend, CLI)
  • Image embedding via ViewHelpers
  • Post-render event to modify the mail content even more

Mail template requirements

Each mail requires at least one of the two template files:

  • The HTML template: Stored in <language>/<ControllerName>/<mailName>.html
  • The TEXT template: Stored in <language>/<ControllerName>/<mailName>.txt

Where:

  • <language> is a ISO-2 language code as configured in the site configuration (lower case)
  • <ControllerName> is the name of the current controller as configured with $mailConfig->controllerName (see below)
  • <mailName> is freely chosen name for the email

Both files are Fluid templates! (within the txt format no HTML escaping is performed)\ Both files need to use UNIX line endings.

Example templates can be found in the template-examples folder of this library.

Mail subject

The template's first lines hold the subject of the mail. The subject line may be blank in one template if you use both templates.

Usage within your extension

function sendMail()
{
    // optional: in a non-frontend environment
    // If your mail needs to contain links to a frontend site,
    // you need a fake FE environment. Consider using reelworx/t3-fakefrontend
    /*
     $fakeFrontend = new FakeFrontendService();
     $fakeFrontend->executeInFEContext($somePublicPageUid, function () {
         // code from below
     });
     */

    // assuming TypoScript settings holds all config (see reference below)
    $mailConfig = MailConfiguration::fromArray($this->settings['mail']);

    $mailConfig->extensionName = 'MyExtension';
    $mailConfig->controllerName = 'Controller';
    $mailConfig->pluginName = 'MyPlugin';

    $mailService = GeneralUtility::makeInstance(MailService::class, $mailConfig);
    $mailService->injectMailer(GeneralUtility::makeInstance(MailerInterface::class));
    $msg = $mailService->createMessage();
    $mailView = $mailService->createMailView($msg, $GLOBALS['TYPO3_REQUEST']);

    $mailView->assign('mydata', 'somedata');

    $mailService->renderToMessage($msg, $mailView, '<mailName>');
    $msg->setTo($someRecipient);

    // optional:
    $msg->attachFromPath($someFalFile->getForLocalProcessing(false));

    $mailService->sendMessage($msg);
}

Extbase controllers

Within Extbase controllers the setup is simplified by using the provided trait.

The important assumption: The mail configuration can be found in $this->settings['mail']

class FooController extends ActionController
{
   use \Reelworx\TYPO3\MailService\ExtbaseMailTrait;

   /* ... */
   public function myAction(): void
   {
       // optional: in a non-frontend environment
       // If your mail needs to contain links to a frontend site,
       // you need a fake FE environment. Consider using reelworx/t3-fakefrontend
       // Example: see above

       //
       // Assumption: TypoScript settings 'mail' holds all mail config (see reference below)
       //
       $this->createMailMessage($mailService, $mailView, $msg);

       $mailView->assign('mydata', 'somedata');

       $mailService->renderToMessage($msg, $mailView, '<mailName>');

       $msg->setTo($someRecipient);

       // optional:
       $msg->attachFromPath($someFalFile->getForLocalProcessing(false));

       $mailService->sendMessage($msg);
   }
}

Post render event to change the mail content

You may optionally equip the MailService with the Core's EventDispatcher, which needs to be injected manually. (The ExtbaseMailTrait already takes care of this for you.)

This allows you to use the MailRenderedEvent.

Register your event handler for the MailRenderedEvent (See TYPO3 documentation)

The event has a getter to retrieve the MailContent object, which you may modify to your needs.

Example usage: Modify the HTML content with some CSS inliner or similar processing tool to get great mail layout quality. Checkout MJML for instance.

Configuration reference

If you configure the mail settings via TypoScript (which you should in order to use the ExtbaseMailTrait) this is how your settings should look like:

plugin.tx_yourext.settings.mail {
    view {
        templateRootPaths.10 = EXT:yourext/Resources/Private/Mail/Templates/
        layoutRootPaths.10 = EXT:yourext/Resources/Private/Mail/Layouts/
        partialRootPaths.10 = EXT:yourext/Resources/Private/Mail/Partials/
    }

    // the following settings are optional
    sender_name = company website
    sender_email = noreply@example.com
    recipient_copy = bcc@example.com
    replyTo = office@example.com
    // this will be the Organization header of messages
    organization = The Company

    // optional: Define allowed languages; The first listed language is used as fallback
    // e.g. Always send mails in EN no matter which language the website run with
    languages = en,de
}

reelworx/t3-mailservice 适用场景与选型建议

reelworx/t3-mailservice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.99k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 01 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 5.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-01-28