diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index aaaa148fde..c801d30493 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -16,6 +16,8 @@ class Mail extends Event protected string $bodyTemplate = ''; protected array $attachment = []; + protected array $customMailOptions = []; + public function __construct(protected Publisher $publisher) { parent::__construct($publisher); @@ -400,6 +402,94 @@ class Mail extends Event return $this; } + /** + * Set sender email + * + * @param string $email + * @return self + */ + public function setSenderEmail(string $email): self + { + $this->customMailOptions['senderEmail'] = $email; + return $this; + } + + /** + * Get sender email + * + * @return string + */ + public function getSenderEmail(): string + { + return $this->customMailOptions['senderEmail'] ?? ''; + } + + /** + * Set sender name + * + * @param string $name + * @return self + */ + public function setSenderName(string $name): self + { + $this->customMailOptions['senderName'] = $name; + return $this; + } + + /** + * Get sender name + * + * @return string + */ + public function getSenderName(): string + { + 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'] ?? ''; + } + /** * Reset * @@ -415,6 +505,7 @@ class Mail extends Event $this->variables = []; $this->bodyTemplate = ''; $this->attachment = []; + $this->customMailOptions = []; return $this; } @@ -436,6 +527,7 @@ class Mail extends Event 'smtp' => $this->smtp, 'variables' => $this->variables, 'attachment' => $this->attachment, + '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 65a295c170..01448620f3 100644 --- a/src/Appwrite/Platform/Workers/Mails.php +++ b/src/Appwrite/Platform/Workers/Mails.php @@ -152,9 +152,21 @@ 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)) { - $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : $smtp['senderEmail']; - $replyToName = $smtp['senderName']; + $customMailOptions = $payload['customMailOptions'] ?? []; + + // fallback hierarchy: Custom options > SMTP config > Defaults. + if (!empty($customMailOptions['senderEmail']) || !empty($customMailOptions['senderName'])) { + $fromEmail = $customMailOptions['senderEmail'] ?? $mail->From; + $fromName = $customMailOptions['senderName'] ?? $mail->FromName; + $mail->setFrom($fromEmail, $fromName); + } + + if (!empty($customMailOptions['replyToEmail']) || !empty($customMailOptions['replyToName'])) { + $replyTo = $customMailOptions['replyToEmail'] ?? $replyTo; + $replyToName = $customMailOptions['replyToName'] ?? $replyToName; + } elseif (!empty($smtp)) { + $replyTo = !empty($smtp['replyTo']) ? $smtp['replyTo'] : ($smtp['senderEmail'] ?? $replyTo); + $replyToName = $smtp['senderName'] ?? $replyToName; } $mail->addReplyTo($replyTo, $replyToName);