FluidMail

class

use TYPO3\CMS\Extbase\Object\ObjectManager;

class FluidMail {
    protected $templateFolder = 'Resources/Private/Templates/Email/';

    protected $objectManager;
    protected $extKey;

    protected $recipient = array();
    protected $sender = array();
    protected $subject = '';

    protected $templateName;
    protected $viewArrayMultiple = array();

    public function __construct() {
        $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
    }
    public function setObjectManager($objectManager){
        $this->objectManager = $objectManager;
    }
    public function setExtKey($extKey){
        $this->extKey = $extKey;
    }
    public function setTemplateName($templateName){
        $this->templateName = $templateName;
    }
    public function setArrayToViewObject($viewArrayMultiple){
        $this->viewArrayMultiple = $viewArrayMultiple;
    }
    public function setTemplateFolder($templateFolder){
        $this->templateFolder = $templateFolder;
    }
    public function setMailParams(array $recipient, array $sender, $subject){
        $this->recipient = $recipient;
        $this->sender = $sender;
        $this->subject = $subject;
    }
    public function send(){
        $emailBody = $this->getHtmlTemplate();
        $message = $this->objectManager->get('TYPO3\CMS\Core\Mail\MailMessage');
        $message->setTo($this->recipient)
            ->setFrom($this->sender)
            ->setSubject($this->subject);
        $message->setBody($emailBody, 'text/html');
        $message->send();
        return $message->isSent();
    }
    protected function getHtmlTemplate(){
        $emailView = $this->objectManager->get('TYPO3\CMS\Fluid\View\StandaloneView');
        $emailView->setTemplatePathAndFilename($this->getTemplatePathAndFilename());
        $emailView->assignMultiple($this->viewArrayMultiple);
        return $emailView->render();

    }
    protected function getTemplatePathAndFilename(){
        return \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:'.$this->extKey.'/'.$this->templateFolder ) . $this->templateName . '.html';
    }
}

Use FluidMail

$fluidMail = new \Vendor\extName\Utility\FluidMail();
$fluidMail->setExtKey($this->extKey);
$fluidMail->setTemplateName('templateName');
$fluidMail->setArrayToViewObject(array('key' => 'value'));
$fluidMail->setMailParams(array('mail@to.de' => 'To'),array('mail@from.de' => 'From'),'hallo');
$fluidMail->send();