Skip to content
Snippets Groups Projects

[FEATURE] Add attachments to mail queue

Merged Kevin Ditscheid requested to merge feature_Attachments into master
7 files
+ 118
5
Compare changes
  • Side-by-side
  • Inline
Files
7
@@ -30,6 +30,7 @@ use SGalinski\SgMail\Domain\Model\Mail;
use SGalinski\SgMail\Service\PlaintextService;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
/**
@@ -92,6 +93,18 @@ class SendMailCommandController extends CommandController {
$plaintextBody = $plaintextService->makePlain($mailBody);
$mailMessage->addPart($plaintextBody, 'text/plain');
$attachments = $mailToSend->getAttachments();
if ($attachments->count() > 0) {
foreach ($attachments as $attachment) {
/**
* @var FileReference $attachment
*/
$file = $attachment->getOriginalResource()->getOriginalFile();
$mailMessage->attach(
\Swift_Attachment::newInstance($file->getContents(), $file->getName(), $file->getMimeType())
);
}
}
try {
$mailMessage->send();
} catch (\Exception $exception) {
Loading