Skip to content
Snippets Groups Projects
Commit 24d21d89 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Adjust mail message attachment and body

parent 73e80dc4
No related branches found
No related tags found
1 merge request!30Feature upgrade to typo3 10
......@@ -32,9 +32,12 @@ use SGalinski\SgMail\Service\PlaintextService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Mime\Part\TextPart;
use TYPO3\CMS\Core\Mail\MailMessage;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
......@@ -104,7 +107,13 @@ class SendMailCommandController extends Command {
$mailMessage->setReplyTo($replyTo);
}
$mailMessage->setBody($mailBody, 'text/html');
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$mailMessage->setBody($mailBody, 'text/html');
} else {
$part = new TextPart($mailBody);
$mailMessage->setBody($part);
}
$plaintextService = GeneralUtility::makeInstance(PlaintextService::class);
$plaintextBody = $plaintextService->makePlain($mailBody);
$mailMessage->addPart($plaintextBody, 'text/plain');
......@@ -113,6 +122,7 @@ class SendMailCommandController extends Command {
if ($attachments->count() > 0) {
foreach ($attachments as $attachment) {
try {
/** @var FileInterface $file */
$file = $attachment->getOriginalResource();
if (!$file) {
continue;
......@@ -122,12 +132,16 @@ class SendMailCommandController extends Command {
if (!$file) {
continue;
}
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
$mailMessage->attach(
\Swift_Attachment::newInstance(
$file->getContents(), $file->getName(), $file->getMimeType()
)
);
} else {
$mailMessage->attach($file->getContents(), $file->getName(), $file->getMimeType());
}
$mailMessage->attach(
\Swift_Attachment::newInstance(
$file->getContents(), $file->getName(), $file->getMimeType()
)
);
} catch (\Exception $exception) {
continue;
}
......
......@@ -283,9 +283,6 @@ Sends your mail or adds it to the mailing queue, depending on the settings. You
###### function sendMailFromQueue
Forces the sending of an E-Mail from within the queue. If it has already been sent, it gets send again.
###### function addAttachment
With this function you can add attachments to your mail. The attachment must be of type *Swift_OutputByteStream*. You must also specify the content-type of the attachment.
###### function getMailMessage
You can get the instance of **\TYPO3\CMS\Core\Mail\MailMessage** that is internally used by the service, if you want a more direct interaction with the mail object.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment