Basic classes for working with Emails on Nette

v2.1.0 2014-07-05 09:16 UTC


Advanced emails with custom templates on Nette


Install the package via composer. Add into your dependencies: "flame/email-package": ">=2.0.0"

Register emails extension


Configure emails via config

        support: [sifalda.jiri@gmail.com, Support]

From this configuration will be created object of Flame\Email\EmailAddress which will be added into Flame\Email\EmailAddressContainer.

Example of usage

Create custom email

use Enlan\UserModule\Entity\User;
use Flame\Email\EmailAddress;
use Flame\Email\IEmailFactory;
use Flame\Email\IFullMessageFactory;
use Nette\Object;

class Mailer extends Object

    /** @var  IEmailFactory */
    private $emailFactory;

    /** @var  IFullMessageFactory */
    private $messageFactory;

     * @param IEmailFactory $emailFactory
     * @param IFullMessageFactory $messageFactory
    function __construct(IEmailFactory $emailFactory, IFullMessageFactory $messageFactory)
        $this->emailFactory = $emailFactory;
        $this->messageFactory = $messageFactory;

     * @param User $user
    public function sendEmailsOnCreate(User $user)
        $message = $this->messageFactory
            ->addTo(new EmailAddress($user->getEmail(), $user->getIdentifier()))

        $email = $this->emailFactory
            ->setTemplateFile(__DIR__ . '/../templates/NewUserEmail.latte');

        $email->template->greeting = 'Hi, all!';

Template file

    <a href="{plink //Homepage: }" target="_blank">Visit homepage</a>

Now, you can use Mailer for sending your advanced Nette emails :-)