From b03aa8d6322db25dfd9e8840f23bc210f6c22d9d Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 10 Dec 2025 14:32:04 +0530 Subject: [PATCH 1/4] 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']; } From 39aa4c4a9a3ad31c5effc0dcbe552d26d407070f Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 10 Dec 2025 15:14:55 +0530 Subject: [PATCH 2/4] add: setfrom. --- src/Appwrite/Platform/Workers/Mails.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 959d6e39e5..5664628754 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -158,6 +158,9 @@ class Mails extends Action if (!empty($senderEmail)) { $replyTo = $senderEmail; $replyToName = $senderName; + + // set again since these can be a diff. + $mail->setFrom($senderEmail, $senderName); } elseif (!empty($smtp)) { $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : $smtp['senderEmail']; $replyToName = $smtp['senderName']; From 205249663503e25e0b15974b777fbbc83f4263fd Mon Sep 17 00:00:00 2001 From: Darshan Date: Fri, 12 Dec 2025 17:41:00 +0530 Subject: [PATCH 3/4] add: support for replyTo* and simplify variables. --- src/Appwrite/Event/Mail.php | 61 +++++++++++++++++++++---- src/Appwrite/Platform/Workers/Mails.php | 29 ++++++++---- 2 files changed, 71 insertions(+), 19 deletions(-) diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index 93e1042f7b..c801d30493 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -16,8 +16,7 @@ class Mail extends Event protected string $bodyTemplate = ''; protected array $attachment = []; - protected string $senderEmail = ''; - protected string $senderName = ''; + protected array $customMailOptions = []; public function __construct(protected Publisher $publisher) { @@ -411,7 +410,7 @@ class Mail extends Event */ public function setSenderEmail(string $email): self { - $this->senderEmail = $email; + $this->customMailOptions['senderEmail'] = $email; return $this; } @@ -422,7 +421,7 @@ class Mail extends Event */ public function getSenderEmail(): string { - return $this->senderEmail; + return $this->customMailOptions['senderEmail'] ?? ''; } /** @@ -433,7 +432,7 @@ class Mail extends Event */ public function setSenderName(string $name): self { - $this->senderName = $name; + $this->customMailOptions['senderName'] = $name; return $this; } @@ -444,7 +443,51 @@ class Mail extends Event */ public function getSenderName(): string { - return $this->senderName; + return $this->customMailOptions['senderName'] ?? ''; + } + + /** + * Set reply-to email + * + * @param string $email + * @return self + */ + public function setReplyToEmail(string $email): self + { + $this->customMailOptions['replyToEmail'] = $email; + return $this; + } + + /** + * Get reply-to email + * + * @return string + */ + public function getReplyToEmail(): string + { + return $this->customMailOptions['replyToEmail'] ?? ''; + } + + /** + * Set reply-to name + * + * @param string $name + * @return self + */ + public function setReplyToName(string $name): self + { + $this->customMailOptions['replyToName'] = $name; + return $this; + } + + /** + * Get reply-to name + * + * @return string + */ + public function getReplyToName(): string + { + return $this->customMailOptions['replyToName'] ?? ''; } /** @@ -462,8 +505,7 @@ class Mail extends Event $this->variables = []; $this->bodyTemplate = ''; $this->attachment = []; - $this->senderEmail = ''; - $this->senderName = ''; + $this->customMailOptions = []; return $this; } @@ -485,8 +527,7 @@ class Mail extends Event 'smtp' => $this->smtp, 'variables' => $this->variables, 'attachment' => $this->attachment, - 'senderEmail' => $this->senderEmail, - 'senderName' => $this->senderName, + 'customMailOptions' => $this->customMailOptions, 'events' => Event::generateEvents($this->getEvent(), $this->getParams()) ]; } diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index ccc665ad85..20f5d1912e 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -152,18 +152,29 @@ 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')); - $senderEmail = $payload['senderEmail'] ?? ''; - $senderName = $payload['senderName'] ?? ''; + $customMailOptions = $payload['customMailOptions'] ?? []; - if (!empty($senderEmail)) { - $replyTo = $senderEmail; - $replyToName = $senderName; + // override sender if custom options are provided. + if (!empty($customMailOptions['senderEmail']) || !empty($customMailOptions['senderName'])) { + // custom email > fallback to default set + $fromEmail = $customMailOptions['senderEmail'] ?? $mail->From; - // set again since these can be a diff. - $mail->setFrom($senderEmail, $senderName); + // custom name > fallback to default set + $fromName = $customMailOptions['senderName'] ?? $mail->FromName; + $mail->setFrom($fromEmail, $fromName); + } + + // override reply-to if custom options provided + if (!empty($customMailOptions['replyToEmail']) || !empty($customMailOptions['replyToName'])) { + // custom reply email > fallback to default set + $replyTo = $customMailOptions['replyToEmail'] ?? $replyTo; + + // custom reply name > fallback to default set + $replyToName = $customMailOptions['replyToName'] ?? $replyToName; } elseif (!empty($smtp)) { - $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : $smtp['senderEmail']; - $replyToName = $smtp['senderName']; + // new smtp options are available, use them! + $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : ($smtp['senderEmail'] ?? $replyTo); + $replyToName = $smtp['senderName'] ?? $replyToName; } $mail->addReplyTo($replyTo, $replyToName); From 37b43b0ce08e296592b90736e4b1b4a977bbc048 Mon Sep 17 00:00:00 2001 From: Darshan Date: Fri, 12 Dec 2025 17:49:48 +0530 Subject: [PATCH 4/4] address comment. --- src/Appwrite/Platform/Workers/Mails.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Mails.php b/src/Appwrite/Platform/Workers/Mails.php index 20f5d1912e..01448620f3 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -154,25 +154,17 @@ class Mails extends Action $customMailOptions = $payload['customMailOptions'] ?? []; - // override sender if custom options are provided. + // fallback hierarchy: Custom options > SMTP config > Defaults. if (!empty($customMailOptions['senderEmail']) || !empty($customMailOptions['senderName'])) { - // custom email > fallback to default set $fromEmail = $customMailOptions['senderEmail'] ?? $mail->From; - - // custom name > fallback to default set $fromName = $customMailOptions['senderName'] ?? $mail->FromName; $mail->setFrom($fromEmail, $fromName); } - // override reply-to if custom options provided if (!empty($customMailOptions['replyToEmail']) || !empty($customMailOptions['replyToName'])) { - // custom reply email > fallback to default set $replyTo = $customMailOptions['replyToEmail'] ?? $replyTo; - - // custom reply name > fallback to default set $replyToName = $customMailOptions['replyToName'] ?? $replyToName; } elseif (!empty($smtp)) { - // new smtp options are available, use them! $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : ($smtp['senderEmail'] ?? $replyTo); $replyToName = $smtp['senderName'] ?? $replyToName; }