From b03aa8d6322db25dfd9e8840f23bc210f6c22d9d Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 10 Dec 2025 14:32:04 +0530 Subject: [PATCH] add: custom senders for cloud. --- src/Appwrite/Event/Mail.php | 51 +++++++++++++++++++++++++ src/Appwrite/Platform/Workers/Mails.php | 8 +++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index aaaa148fde..93e1042f7b 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -16,6 +16,9 @@ class Mail extends Event protected string $bodyTemplate = ''; protected array $attachment = []; + protected string $senderEmail = ''; + protected string $senderName = ''; + public function __construct(protected Publisher $publisher) { parent::__construct($publisher); @@ -400,6 +403,50 @@ class Mail extends Event return $this; } + /** + * Set sender email + * + * @param string $email + * @return self + */ + public function setSenderEmail(string $email): self + { + $this->senderEmail = $email; + return $this; + } + + /** + * Get sender email + * + * @return string + */ + public function getSenderEmail(): string + { + return $this->senderEmail; + } + + /** + * Set sender name + * + * @param string $name + * @return self + */ + public function setSenderName(string $name): self + { + $this->senderName = $name; + return $this; + } + + /** + * Get sender name + * + * @return string + */ + public function getSenderName(): string + { + return $this->senderName; + } + /** * Reset * @@ -415,6 +462,8 @@ class Mail extends Event $this->variables = []; $this->bodyTemplate = ''; $this->attachment = []; + $this->senderEmail = ''; + $this->senderName = ''; return $this; } @@ -436,6 +485,8 @@ class Mail extends Event 'smtp' => $this->smtp, 'variables' => $this->variables, 'attachment' => $this->attachment, + 'senderEmail' => $this->senderEmail, + 'senderName' => $this->senderName, 'events' => Event::generateEvents($this->getEvent(), $this->getParams()) ]; } diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index efca484ebf..959d6e39e5 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -152,7 +152,13 @@ class Mails extends Action $replyTo = System::getEnv('_APP_SYSTEM_EMAIL_ADDRESS', APP_EMAIL_TEAM); $replyToName = \urldecode(System::getEnv('_APP_SYSTEM_EMAIL_NAME', APP_NAME . ' Server')); - if (!empty($smtp)) { + $senderEmail = $payload['senderEmail'] ?? ''; + $senderName = $payload['senderName'] ?? ''; + + if (!empty($senderEmail)) { + $replyTo = $senderEmail; + $replyToName = $senderName; + } elseif (!empty($smtp)) { $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : $smtp['senderEmail']; $replyToName = $smtp['senderName']; }