From 686fff945e0b4697aa74da404ce90534bb7b121d Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Thu, 26 Dec 2024 20:12:34 +0100 Subject: Add async email and topic subscribing --- src/application/jobs/email.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/application/jobs/email.php (limited to 'src/application/jobs/email.php') diff --git a/src/application/jobs/email.php b/src/application/jobs/email.php new file mode 100644 index 0000000..8bb97dc --- /dev/null +++ b/src/application/jobs/email.php @@ -0,0 +1,33 @@ +fetchAll(PendingEmail::class); + +$transport = Transport::fromDsn(getenv("MAILER_DSN")); + +foreach ($pendingEmails as $pendingEmail) { + try { + $mail = (new Email) + ->from($pendingEmail->sender) + ->to($pendingEmail->recipient) + ->subject($pendingEmail->subject) + ; + if (!empty($pendingEmail->htmlBody)) + $mail->html($pendingEmail->htmlBody); + if (!empty($pendingEmail->plaintextBody)) + $mail->text($pendingEmail->plaintextBody); + $transport->send($mail); + } catch (TransportExceptionInterface $ex) { + print_error("Failed to send mail: " . $ex->getMessage() . "\n"); + } + $db->delete($pendingEmail); +} -- cgit v1.2.3