2020-06-14 06:30:44 +12:00
|
|
|
<?php
|
|
|
|
|
2021-03-10 21:08:17 +13:00
|
|
|
use Appwrite\Resque\Worker;
|
2020-07-06 09:54:41 +12:00
|
|
|
use Utopia\App;
|
2020-11-21 12:44:00 +13:00
|
|
|
use Utopia\CLI\Console;
|
2020-07-06 09:54:41 +12:00
|
|
|
|
2020-06-14 06:30:44 +12:00
|
|
|
require_once __DIR__.'/../init.php';
|
|
|
|
|
2021-01-15 19:02:48 +13:00
|
|
|
Console::title('Mails V1 Worker');
|
2020-06-14 06:30:44 +12:00
|
|
|
|
2020-12-19 21:08:03 +13:00
|
|
|
Console::success(APP_NAME.' mails worker v1 has started'."\n");
|
2020-06-14 06:30:44 +12:00
|
|
|
|
2021-03-10 21:08:17 +13:00
|
|
|
class MailsV1 extends Worker
|
2020-06-14 06:30:44 +12:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $args = [];
|
|
|
|
|
2021-03-10 21:08:17 +13:00
|
|
|
public function init(): void
|
2020-06-14 06:30:44 +12:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-03-10 21:08:17 +13:00
|
|
|
public function execute(): void
|
2020-06-14 06:30:44 +12:00
|
|
|
{
|
|
|
|
global $register;
|
|
|
|
|
2020-11-21 12:44:00 +13:00
|
|
|
if(empty(App::getEnv('_APP_SMTP_HOST'))) {
|
2020-11-21 19:26:22 +13:00
|
|
|
Console::info('Skipped mail processing. No SMTP server hostname has been set.');
|
2020-11-21 12:44:00 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-14 11:06:05 +12:00
|
|
|
$event = $this->args['event'];
|
2020-07-06 09:54:41 +12:00
|
|
|
$from = $this->args['from'];
|
2020-06-14 06:30:44 +12:00
|
|
|
$recipient = $this->args['recipient'];
|
|
|
|
$name = $this->args['name'];
|
|
|
|
$subject = $this->args['subject'];
|
|
|
|
$body = $this->args['body'];
|
|
|
|
|
2020-07-06 09:54:41 +12:00
|
|
|
/** @var \PHPMailer\PHPMailer\PHPMailer $mail */
|
|
|
|
$mail = $register->get('smtp');
|
|
|
|
|
|
|
|
// Set project mail
|
|
|
|
/*$register->get('smtp')
|
|
|
|
->setFrom(
|
|
|
|
App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM),
|
|
|
|
($project->getId() === 'console')
|
|
|
|
? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server'))
|
|
|
|
: \sprintf(Locale::getText('account.emails.team'), $project->getAttribute('name')
|
|
|
|
)
|
|
|
|
);*/
|
|
|
|
|
|
|
|
$mail->clearAddresses();
|
|
|
|
$mail->clearAllRecipients();
|
|
|
|
$mail->clearReplyTos();
|
|
|
|
$mail->clearAttachments();
|
|
|
|
$mail->clearBCCs();
|
|
|
|
$mail->clearCCs();
|
2020-06-14 06:30:44 +12:00
|
|
|
|
2020-07-06 09:54:41 +12:00
|
|
|
$mail->setFrom(App::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM), (empty($from) ? \urldecode(App::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME.' Server')) : $from));
|
2020-06-14 06:30:44 +12:00
|
|
|
$mail->addAddress($recipient, $name);
|
|
|
|
$mail->Subject = $subject;
|
|
|
|
$mail->Body = $body;
|
2020-06-20 23:20:49 +12:00
|
|
|
$mail->AltBody = \strip_tags($body);
|
2020-06-14 06:30:44 +12:00
|
|
|
|
|
|
|
try {
|
|
|
|
$mail->send();
|
|
|
|
} catch (\Exception $error) {
|
|
|
|
throw new Exception('Error sending mail: ' . $error->getMessage(), 500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 21:08:17 +13:00
|
|
|
public function shutdown(): void
|
2020-06-14 06:30:44 +12:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|