Coder Social home page Coder Social logo

swiftmailer-manipulator-bundle's Introduction

Swiftmailer Manipulator for Symfony

Build Status Scrutinizer Code Quality Code Coverage Code Style

Sometimes you have staging systems, where you can't install MailHog and using delivery_address or disable_delivery on the SwiftmailerBundle is not enough. For example your customer wants the mail to be really delivered.

But maybe the crafted mail goes to a partner, retailer, user, whatever and now they are worried why they got them (for example notification systems).

This bundle can help you! It provides a plugin into Swiftmailer, which allows you to modify the subject or body or the from address of every message before delivery.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require pixelart/swiftmailer-manipulator-bundle ^1.0

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Pixelart\Bundle\SwiftmailerManipulatorBundle\PixelartSwiftmailerManipulatorBundle(),
        );

        // ...
    }

    // ...
}

For more informations, see the configuration page.

Full configuration options

# app/config/config.yml

pixelart_swiftmailer_manipulator:
    mailers:
        first_mailer:
            prepend_subject: 'String prepend to subject'  # String which is prepended onto the subject
            prepend_body: 'path/to/prepend_body.txt.twig' # Path to template which is prepended onto the mail body
            from_address: '[email protected]'      # The address message should be sent from
        second_mailer:
            # ...

Contributing

The contributing guidelines contains all the information about contributing to the bundle.

Bug tracking

We use GitHub issues and waffle.io board to track issues. If you have found bug, please create an issue.

MIT License

License can be found here.

Code of Conduct

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code.

swiftmailer-manipulator-bundle's People

Contributors

angelov avatar nykopol avatar quingkhaos avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

angelov nykopol

swiftmailer-manipulator-bundle's Issues

Add from address impersonation plugin

Q A
Bug? no
New Feature? yes

Add a new ImpersonatePlugin which really modifies the from address of the message sent.

Use case

When sending from staging/test systems within you network, but all the from address settings are already configured to the project domain (e.g. because the DB is synced from production every while), then those messages are not delivered due SPF and spam detection.

Thus the from address domain must be a address from the staging system is in control (SPF records are correct, etc.)

The sender_address of the SwiftmailerBundle is not sufficient for this case, as it modifies the Return-Path header which determines an address where bounce message and co should go. This is more a setting for production.

Additional informations

It's really similar to the Swift_Plugins_ImpersonatePlugin from Swiftmailer itself but modifying the From header.

The configuration in the bundle should be a simple parameter from_address.

Refactor manipulator plugin configuration

Q A
Bug? no
New Feature? no
This Bundle Version 1.0.0

Refactor the manipulator configuration in the extension into it's own method to have a clean code base for adding other plugins.

Support multipart messages and templates for the correct content type

Q A
Bug? not really, but missing functionality
New Feature? thus an ehancement
This Bundle Version 1.0.0

Actual Behavior

At the moment only the main body is prepended, but not any child part for e.g. sending plain and html messages. And the content type of the body is ignored too.

Expected Behavior

The manipulator should prepend optional child parts too. And it should accept two templates too, applied to either text or html messages.

Steps to Reproduce

public function indexAction($name)
{
    $message = \Swift_Message::newInstance()
        ->setSubject('Hello Email')
        ->setFrom('[email protected]')
        ->setTo('[email protected]')
        ->setBody(
            $this->renderView(
                // app/Resources/views/Emails/registration.html.twig
                'Emails/registration.html.twig',
                array('name' => $name)
            ),
            'text/html'
        )
        ->addPart(
            $this->renderView(
                'Emails/registration.txt.twig',
                array('name' => $name)
            ),
            'text/plain'
        )
    ;
    $this->get('mailer')->send($message);

    return $this->render(...);
}

And only the html message will be prepended if a prepend_body template is configured.

Possible Solutions

Configure the prepend_body configuration it a way that it either accepts a single string value as template for both html and plaintext or that it accepts two templates for them.

Then in the manipulator plugin you have to analyze the body which content type is used and render the correct template. Then you have to inspect the child parts if they are a multipart body. A multipart body children is an instance of Swift_Mime_MimePart in $message->getChildren()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.