2017 © Pedro Peláez
 

everlution-bundle email-bundle-2

Everlution email bundle for Symfony framework

image

everlutionsk/email-bundle-2

Everlution email bundle for Symfony framework

  • Friday, December 8, 2017
  • by everlution
  • Repository
  • 7 Watchers
  • 1 Stars
  • 3,820 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 3 Open issues
  • 19 Versions
  • 1 % Grown

The README.md

Email Bundle

This Symfony bundle provides mechanism for sending and receiving email messages through various mail systems., (*1)

Installation

composer require everlutionsk/email-bundle-2

Enable the bundle

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Everlution\EmailBundle\EverlutionEmailBundle()
    );
}

Configure the bundle

Following configuration snippet describes how to configure the bundle. Configuration requires a names of services, which implements corresponding interfaces. Only exception is doman_name, where you should set something like appdomain.com, (*2)

# app/config/config.yml

# Doctrine Configuration
doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    EverlutionEmailBundle: ~

# EmailBundle Configuration
everlution_email:
    domain_name: APP_DOMAIN
    enforced_delivery_address: EMAIL_ADDRESS|NULL
    mail_system: Implementation of Outbound\MailSystem\MailSystem
    async_stream: Implementation of Support\Stream\Stream
    attachment_swappers:
        inbound: Implementation of Inbound\Attachment\AttachmentSwapper
        outbound: Implementation of Outbound\Attachment\AttachmentSwapper
    request_processors:
        inbound: Implementation of Inbound\RequestProcessor
        outbound_message_event: Implementation of Outbound\MessageEvent\RequestProcessor

mail_system - Name of service, which will be used for sending email messages. This service usually comunicate with SMTP server or with some transactional email platform like Mandrill., (*3)

enforced_delivery_address - [Optional] Email address, which will be used to override recipient address in every outbound message., (*4)

async_stream - Bundle allows to send email messages asynchronously. Email messages is stored in memory unil some value is added into this Stream. Good example is a Stream of Symfony's kernel.terminate events., (*5)

attachment_swappers - After sending or receiving a message, bundle try to save the message's attachments by using this attachment swappers. This swappers can save attachments in various ways., (*6)

request_processors - Bundle provide common mechanism to handle inbound messages and outbound message events. This events may occur for example when external mail system try to send scheduled messages. However, different mail systems sending data in different format. Request processors transform this data into format, which is known for this bundle., (*7)

Routing

Bundle provides controllers for handling inbound messages and outbound message events., (*8)

# Handle outbound message events.
everlution.email.outbound_message_event:
    pattern: CUSTOM_PATTERN
    defaults: { _controller: everlution.email.outbound.message_event.controller:handleMessageEvent }
    methods: POST

# Handle inbound messages.
everlution.email.inbound:
    pattern: CUSTOM_PATTERN
    defaults: { _controller: everlution.email.inbound.controller:handleInbound }
    methods: POST

Basic Usage

Create new outbound message

$message = new OutboundMessage();
$message->setSubject('Subject');
$message->setText('Message text.');             // Text for basic insight in email client.
$message->setHtml('<img src="cid:logo">');      // Email body.
$message->setFromEmail('support@example.com');
$message->setFromName('Sender name');
$message->setReplyTo('reply@example.com');
$message->setRecipients([
    new ToRecipient('recipient@mail.com', 'Recipient name'),
    new CcRecipient('cc-recipient@mail.com', 'Cc recipient name'),
    new BccRecipient('bcc-recipient@mail.com', 'Bcc recipient name'),
]);

$image = new BasicAttachment('image/png', 'logo', file_get_contents('logo.png'));
$attachment = new BasicAttachment('application/pdf', 'document.pdf', file_get_contents('document.pdf'));

$message->setImages([$image]);            // Images included into email body. 
$message->setAttachments([$attachment]);

Get mailer

Synchronous mailer - Mail system is called immediately., (*9)

$mailer = $this->get('everlution.email.outbound.synchronous_mailer');

Asynchronous mailer - Mail system is called after adding value into corresponding Stream., (*10)

$mailer = $this->get('everlution.email.outbound.asynchronous_mailer');

Send / Schedule message

$mailer->sendMessage($message);
$mailer->scheduleMessage($message, new \DateTime('+ 30 minutes'));

Advanced usage

Message transformers

Every message could be modified before it is forwarded into mail system., (*11)

Transforming outbound messages
Register service, which implements OutboundMessageTransformer and add following tag:, (*12)

everlution.email.outbound.message_transformer

Transforming inbound messages
Register service, which implements InboundMessageTransformer and add following tag:, (*13)

everlution.email.inbound.message_transformer

Message templates

Some mail systems supports message templates, which are defined in this systems. The following code shows how to use this templates., (*14)

$parameter = new Parameter('PARAMETER_NAME', 'PARAMETER_VALUE');
$template = new Template('TEMPLATE_NAME', [$parameter]);

$message->setTemplate($template);

Handle Inbound messages

Inbound messages can be handled by listeners, which listening to everlution.email.inbound events. Events are instances of InboundEvent and contains information about Inbound message and about its storable version, which has been saved into database., (*15)


, (*16)

Caution: If application doesn't need to create associations with inbound message in database, then storable version of message should be ignored., (*17)

Mock a mail system

Use everlution.email.mock.mail_system service as mail system (see Configure the bundle section)., (*18)

Supported mail systems

Mandrill, (*19)

The Versions

08/12 2017

dev-master

9999999-dev

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

08/12 2017

1.4.0

1.4.0.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

15/11 2017

1.3.0

1.3.0.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

14/11 2017

dev-sf4

dev-sf4

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

13/07 2017

1.2.5

1.2.5.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

25/08 2016

1.2.4

1.2.4.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

21/07 2016

1.2.3

1.2.3.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

02/02 2016

1.2.2

1.2.2.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

29/01 2016

1.2.1

1.2.1.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

20/01 2016

1.2.0

1.2.0.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

12/01 2016

dev-symfony3

dev-symfony3

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

08/01 2016

1.1.3

1.1.3.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

26/10 2015

1.1.2

1.1.2.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

26/10 2015

1.1.1

1.1.1.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

06/10 2015

1.1.0

1.1.0.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

05/10 2015

1.0.3

1.0.3.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

01/10 2015

1.0.2

1.0.2.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

01/10 2015

1.0.1

1.0.1.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution

21/09 2015

1.0.0

1.0.0.0

Everlution email bundle for Symfony framework

  Sources   Download

MIT

The Requires

 

by Tomas Szabo

email bundle symfony everlution