in2code-de / powermail

This is the official repository of the TYPO3 extension powermail! Powermail is a well-known, editor-friendly, powerful and easy mailform extension for TYPO3
https://in2code.de
88 stars 175 forks source link

Signal "sendTemplateEmailBeforeSend" not working #170

Closed chequille closed 7 years ago

chequille commented 7 years ago

Hi Alex, sorry to bring this up again. You told me to try this signal to attach f.e. a PDF File to the email. Unfortunately, this Signal is not woriking. More than this, the further processing is stopping. This means that the mail is not send anymore. I tried it as well with your powermailextended sample extension. It is not working there as well . (of course I removed the FormController part which compares the given email addresses).

Can you have a look into it please? BR Jürgen

einpraegsam commented 7 years ago

I just tested it and it works like a charm. I use the signal sendTemplateEmailBeforeSend to always attach a file from fileadmin to every email (in powermail 3.22.1 and TYPO3 8.7.6):

ext_localconf.php from my powermailaddition extension:

<?php
/**
 * Register some Slots
 */
/** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
    \TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class
);

// Change receiver mail example
$signalSlotDispatcher->connect(
    \In2code\Powermail\Domain\Service\SendMailService::class,
    'sendTemplateEmailBeforeSend',
    \In2code\Powermailextended\Domain\Service\SendMailService::class,
    'manipulateMail',
    false
);

SendMailServer.php from my powermailaddition extension:

<?php
namespace In2code\Powermailextended\Domain\Service;

use In2code\Powermail\Domain\Service\SendMailService as SendMailServicePowermail;
use TYPO3\CMS\Core\Mail\MailMessage;

/**
 * Class SendMailService
 */
class SendMailService
{

    /**
     * Manipulate message object short before powermail send the mail
     *
     * @param MailMessage $message
     * @param array $email
     * @param SendMailServicePowermail $sendMailService
     */
    public function manipulateMail($message, &$email, SendMailServicePowermail $sendMailService)
    {
        $file = '/var/www/html/powermail.localhost.de/fileadmin/user_upload/dalmatiner.png';
        $message->attach(\Swift_Attachment::fromPath($file));
    }
}

What else should I do to reproduce the issue?

chequille commented 7 years ago

Hi Alex,

thanks for this answer.

The only difference to my tests is that I am using Typo3 7.6.22 and not 8.7.6. Maybe there is a different behaviour regarding the Extbase SignalDispatch classes in Typo3 8.x.x

I do not have an Typo3 Version 8 installation currently, but I plan to do this soon. I will try it again this evening on my Typo3 7 installation exactly with the part from your answer. Maybe you can test it as well on a Typo3 7 installtion if you have a little time.

I come back to you with my results as soon as I have it.

Thanks and BR Jürgen

einpraegsam commented 7 years ago

Sorry, but I have to do paid work first. This was just a quickwin. I will close this issue now because it seems to work as expected.

chequille commented 7 years ago

Hi Alex, wanted to tell you, that it is working as well in typo3 7.6.22 :-) I think I found why it was not working before my changes.

I tried to add the signal to the other extension for generating the PDF file. This extension is registering the signal as following:

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect( 'In2code\\Powermail\\Controller\\FormController', 'createActionAfterMailDbSaved', 'Bvt\\BvtPowermailPdf\\PdfGen', 'createAction' );

Of course, I did it for the other signal in the same way:

\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\SignalSlot\\Dispatcher')->connect( 'In2code\\Powermail\\Domain\\Service\\SendMailService', 'sendTemplateEmailBeforeSend', 'Bvt\\BvtPowermailPdf\\SendMailService, 'manipulateMail' ); This did not work.

It works when I changed the code to the way you showed me in your post above:

$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( \TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class ); $signalSlotDispatcher->connect( \In2code\Powermail\Controller\FormController::class, 'createActionBeforeRenderView', \Bvt\BvtPowermailPdf\PdfGen::class, 'createAction', false ); // Change receiver mail example $signalSlotDispatcher->connect( \In2code\Powermail\Domain\Service\SendMailService::class, 'sendTemplateEmailBeforeSend', \Bvt\BvtPowermailPdf\SendMailService::class, 'manipulateMail', false );

Do not know where the difference is, because the other signal did work, but not the "sendTemplateEmailBeforeSend".

So, thanks again for your help. BR Jürgen

einpraegsam commented 7 years ago

Thx for the final feedback