From 754587025d31834d7fbb6bc54143ce03072a84d9 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 6 Dec 2023 13:56:02 +0100 Subject: [PATCH] support body template attribute for emails --- src/Appwrite/Event/Mail.php | 25 +++++++++++++++++++++++++ src/Appwrite/Platform/Workers/Mails.php | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index c2de8023b0..6cb53d4d36 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -13,6 +13,7 @@ class Mail extends Event protected string $body = ''; protected array $smtp = []; protected array $variables = []; + protected string $bodyTemplate = ''; public function __construct(protected Connection $connection) { @@ -115,6 +116,29 @@ class Mail extends Event return $this->name; } + /** + * Sets bodyTemplate for the mail event. + * + * @param string $bodyTemplate + * @return self + */ + public function setbodyTemplate(string $bodyTemplate): self + { + $this->bodyTemplate = $bodyTemplate; + + return $this; + } + + /** + * Returns subject for the mail event. + * + * @return string + */ + public function getbodyTemplate(): string + { + return $this->bodyTemplate; + } + /** * Set SMTP Host * @@ -327,6 +351,7 @@ class Mail extends Event 'recipient' => $this->recipient, 'name' => $this->name, 'subject' => $this->subject, + 'bodyTemplate' => $this->bodyTemplate, 'body' => $this->body, 'smtp' => $this->smtp, 'variables' => $this->variables, diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 94a2a46087..604169c484 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -59,8 +59,8 @@ class Mails extends Action $variables = $payload['variables']; $name = $payload['name']; $body = $payload['body']; - - $bodyTemplate = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'); + $bodyTemplate = $payload['bodyTemplate'] ?? __DIR__ . '/../../../../app/config/locale/templates/email-base.tpl'; + $bodyTemplate = Template::fromFile($bodyTemplate); $bodyTemplate->setParam('{{body}}', $body); foreach ($variables as $key => $value) { $bodyTemplate->setParam('{{' . $key . '}}', $value);