From 8d07da3e4ec4cbf73157cc13eed8aaa3f4346212 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 14 Jul 2026 10:16:12 +0530 Subject: [PATCH] fix: restore branding for recovery emails --- app/controllers/api/account.php | 23 +++++++++++++ .../Account/AccountConsoleClientTest.php | 34 +++++++++++++++++++ .../Account/AccountCustomClientTest.php | 1 + 3 files changed, 58 insertions(+) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index add569b4fc..c46c6bbafa 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -3827,6 +3827,14 @@ Http::post('/v1/account/recovery') $customTemplate = $project->getAttribute('templates', [])['email.recovery-' . $locale->default] ?? $project->getAttribute('templates', [])['email.recovery-' . $locale->fallback] ?? []; + $smtpBaseTemplate = $project->getAttribute('smtpBaseTemplate', 'email-base'); + + $validator = new FileName(); + if (!$validator->isValid($smtpBaseTemplate)) { + throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Invalid template path'); + } + + $bodyTemplate = __DIR__ . '/../../config/locale/templates/' . $smtpBaseTemplate . '.tpl'; $message = Template::fromFile(__DIR__ . '/../../config/locale/templates/email-inner-base.tpl'); $message @@ -3906,12 +3914,27 @@ Http::post('/v1/account/recovery') 'team' => '' ]; + if ($smtpBaseTemplate === APP_BRANDED_EMAIL_BASE_TEMPLATE) { + $emailVariables = [ + ...$emailVariables, + 'accentColor' => $platform['accentColor'], + 'logoUrl' => $platform['logoUrl'], + 'twitter' => $platform['twitterUrl'], + 'discord' => $platform['discordUrl'], + 'github' => $platform['githubUrl'], + 'terms' => $platform['termsUrl'], + 'privacy' => $platform['privacyUrl'], + 'platform' => $platform['platformName'], + ]; + } + $publisherForMails->enqueue(new MailMessage( project: $project, recipient: $profile->getAttribute('email', ''), name: $profile->getAttribute('name', ''), subject: $subject, template: MAIL_TEMPLATE_RECOVERY, + bodyTemplate: $bodyTemplate, body: $body, preview: $preview, smtp: $smtpConfig, diff --git a/tests/e2e/Services/Account/AccountConsoleClientTest.php b/tests/e2e/Services/Account/AccountConsoleClientTest.php index a4b5ea2e2f..c8fda2b5f6 100644 --- a/tests/e2e/Services/Account/AccountConsoleClientTest.php +++ b/tests/e2e/Services/Account/AccountConsoleClientTest.php @@ -16,6 +16,40 @@ final class AccountConsoleClientTest extends Scope use ProjectConsole; use SideClient; + public function testCreateRecoveryEmailBranding(): void + { + $email = ID::unique() . '@appwrite.io'; + + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => 'password', + 'name' => 'Recovery User', + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_POST, '/account/recovery', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'url' => 'http://localhost/recovery', + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + $lastEmail = $this->getLastEmailByAddress($email); + + $this->assertNotEmpty($lastEmail, 'Email not found for address: ' . $email); + $this->assertStringContainsStringIgnoringCase('Appwrite logo', $lastEmail['html']); + } + /** * Test that account deletion succeeds even with active team memberships. * When the user is the sole owner and only member of a team, the team diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index e59e6752ae..403944e6b2 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -1804,6 +1804,7 @@ final class AccountCustomClientTest extends Scope $this->assertEquals($name, $lastEmail['to'][0]['name']); $this->assertEquals('Password Reset for ' . $this->getProject()['name'], $lastEmail['subject']); $this->assertStringContainsStringIgnoringCase('Reset your ' . $this->getProject()['name'] . ' password using the link.', $lastEmail['text']); + $this->assertStringNotContainsStringIgnoringCase('Appwrite logo', $lastEmail['html']); $tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html']);