add mms files to mail transfert

This commit is contained in:
osaajani 2021-04-03 18:19:08 +02:00
parent d29424ff0c
commit e06079e6af
5 changed files with 17 additions and 5 deletions

View File

@ -101,10 +101,11 @@ class Mailer extends \descartes\Controller
* @param string $destination : email address to send email to
* @param array $settings : Email settings
* @param array $data : Data to inject into email template
* @param array $attachments : List of paths of files to attach to the mail
*
* @return bool : true on success, false on error
*/
public function enqueue(string $destination, array $settings, array $data): bool
public function enqueue(string $destination, array $settings, array $data, array $attachments = []): bool
{
$response = $this->generate_body($settings, $data);
@ -113,6 +114,7 @@ class Mailer extends \descartes\Controller
'subject' => $settings['subject'],
'body' => $response['body'],
'alt_body' => $response['alt_body'],
'attachments' => $attachments,
];
$error_code = null;

View File

@ -291,12 +291,20 @@ namespace controllers\internals;
}
$mailer = new Mailer();
$attachments = [];
foreach ($received['medias'] ?? [] as $media)
{
$attachments[] = PWD_DATA_PUBLIC . '/' . $media['path'];
}
return $mailer->enqueue($user['email'], EMAIL_TRANSFER_SMS, [
'at' => $received['at'],
'origin' => $received['origin'],
'destination' => $phone['name'],
'text' => $received['text'],
]);
'mms' => $received['mms'] ?? false,
], $attachments);
}
}

View File

@ -74,7 +74,7 @@ class Mailer extends AbstractDaemon
$this->logger->info('Try sending email : ' . json_encode($message));
$mailer = new \controllers\internals\Mailer();
$success = $mailer->send($message['destinations'], $message['subject'], $message['body'], $message['alt_body']);
$success = $mailer->send($message['destinations'], $message['subject'], $message['body'], $message['alt_body'], $message['attachments']);
if (!$success)
{
$this->logger->error('Failed sending email');

View File

@ -17,6 +17,8 @@
'PWD_ADAPTERS' => PWD . '/adapters',
'PWD_DATA' => PWD . '/data',
'HTTP_PWD_DATA' => HTTP_PWD . '/data',
'PWD_DATA_PUBLIC' => PWD . '/data/public',
'HTTP_PWD_DATA_PUBLIC' => HTTP_PWD . '/data/public',
'PWD_LOGS' => '/var/log/raspisms',
'PWD_PID' => '/var/run/raspisms',
'APP_SECRET' => '%APP_SECRET%',
@ -67,7 +69,7 @@
'preferred_phone_country' => 'fr,be,ca',
'default_phone_country' => 'fr',
'authorized_phone_country' => 'fr,be,ca',
'mms' => 0,
'mms' => 1,
],
];

View File

@ -1,4 +1,4 @@
Vous avez reçu un nouveau SMS :
Vous avez reçu un nouveau <?= $mms ? 'MMS' : 'SMS'; ?> :
Date : <?= $at ?>
Origine : <?= $origin ?>