定制 ite/mail-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

ite/mail-bundle

Composer 安装命令:

composer require ite/mail-bundle

包简介

Provides functional for send emails using email templates and less generating functionality for end emails

README 文档

README

Provides functional for send emails using email templates and less generating functionality for end emails

Installation and configuration:

Pretty simple with Composer, run:

composer require ite/mail-bundle

Configuration example

You can configure default parameters for email senders and using styles for email templates

ite_mail:
    bcc_email: %bcc_email%
    from_email: %support_email%
    support_email: %support_email%
    noreply_email: %noreply_email%
    template_folder: AcmeCoreBundle:Email/Template #folder with all email templates
    styles: ['@AcmeCoreBundle/Resources/public/less/email/style.less', '@AcmeCoreBundle/Resources/public/less/email/style2.less'] #additional styles for email templates will be generated to inline styles in end email
    translation_domain: email_subjects #provide translations for end email subjects

Add ITEMailBundle to your application kernel

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
            new ITE\MailBundle\ITEMailBundle(),
        // ...
    );
}

Usage examples:

Add Extension

Create tokens based on context name

// src/Acme/CoreBundle/Extension/Mail
namespace Acme\CoreBundle\Extension\Mail;

use ITE\MailBundle\Extension\BaseExtension;
use ITE\MailBundle\Extension\TokenExtensionInterface;
use ITE\MailBundle\Token\Context;
use ITE\MailBundle\Token\Token;
use Symfony\Component\DependencyInjection\ContainerInterface;

class MainExtension extends BaseExtension implements TokenExtensionInterface
{

    private $twig;
    
    private $container;
    
    /**
     * @param ContainerInterface $container
     * @internal param $twig
     */
    function __construct(ContainerInterface $container)
    {
        $this->container = $container;
        $this->twig = $container->get('twig');
    }

    /**
     * Retrieve token list depend on token context
     *
     * @param Context $context
     *
     * @return Token[]
     */
    public function getTokens(Context $context)
    {
        $this->setContext($context);
        $data = $context->getData();
        switch ($context->getName()) {
            case 'test_context_name':
                return [
                    new Token('test_token', $data['someData'], 'Test Token'),
                ];
                break;
        }

        return [];
    }

    public function setContext(Context $context)
    {
        if ($context->getData()) {
            return null;
        }
    }

    /**
     * Retrieve global token list, not depended on context
     *
     * @return Token[]
     */
    public function getGlobals()
    {
        return [];
    }

} 

Add Extension to Services

Add mail extension to services.yml

services:
    admin.mail.token.main_extension:
        class: Acme\CoreBundle\Extension\Mail\MainExtension
        arguments: [@service_container]
        tags:
            - {name: ite.mail.extension}

Add template to AcmeCoreBundle:Email/Template folder (template_folder in config.yml)

Create the template test_template.html.twig in AcmeCoreBundle:Email/Template folder

Hi User,
[test_token] {#This is the token name from Acme\CoreBundle\Extension\Mail\MainExtension#}

Controller

You can send email using template test_template.html.twig:

// Acme\MainBundle\Controller\ArticleController.php

    public function sendAction()
    {
        $data = ['someData' => 123];
        $this
            ->get('ite.mail.manager')
            ->mail('test_template', 'some_email@mail.com', 'Some subject', [
                'token_context' => new Context($data, 'test_context_name')
            ]);

        return [];
    }

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 5
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-05