Project

General

Profile

Actions

Feature #64047

closed

extbase mail wrapper for core mail; ActionMailer

Added by Pascal Dürsteler almost 10 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2014-12-27
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

The current way to go when implementing mail delivery in an extbase extension seems to be http://wiki.typo3.org/How_to_use_the_Fluid_Standalone_view_to_render_template_based_emails. Peeking at out ActionController, extbase could provide the same architecture for looking up and rendering mails.

I'm just throwing my idea in here with a bit of pseudo-code, as this may explain things better than when writing it out. IMHO this would help extension developers to concentrate on building their extension and spare a lot of time writing / copy-pasting code to handle mail deliveries.

File structure

typo3conf/ext/<myext>
  - Classes
    - Mailer
      - MyMailer.php
  - Resources
    - Private
      - Templates
        - MyMailer

MyMailer.php

class MyMailer extends \TYPO3\CMS\Extbase\Mailer\ActionMailer {
    public function welcomeUserMail($user) {
        /** @var \TYPO3\Core\Mail\Message */
        $mail = $this->createMail();

        /* 
          * ActionMailer base class sets layout and template automagically
          * based on the current controller name and action name; This e.g. would be 
          *
          *   $templateRootPath/@MailerClassName/@MailerMethodName.html
          *
          * The only thing you actually do in here is set / assign data, similiar to the controller.
          */

        $mail->setTo($user->getEmail());
        $mail->setSubject('Successfully signed up!');
        $mail->assign('user', $user); // Exposed to the fluid standalone view
        return $mail->send();
    }
}

MyController.php

public function confirmationAction() {
    // ... creating $user ...

    $mailer = makeInstance('MyMailer'); // or maybe instantiate it through DI's @inject?
    $mailer->welcomeUserMail($user);
}


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Feature #90266: Fluid-based templated emailsClosedBenni Mack2020-01-31

Actions
Actions

Also available in: Atom PDF